fix printFloat
- Move buffer malloc into adafruit_fifo constructor - allo BLEUart to set fifo size
This commit is contained in:
1 parent
d1377d12e6
commit
cfd3b86533
5 files changed
+27
-12
No files matched your search
@@ -41,24 +41,34 @@
|
||||
/*!
|
||||
@brief Constructor
|
||||
|
||||
@param[in] buffer
|
||||
Memory location to store data
|
||||
@param[in] depth
|
||||
Maximum number of items can be hold in buffer
|
||||
@param[in] item_size
|
||||
Number of bytes of each item
|
||||
@param[in] overwrite
|
||||
Should the buffer is overwitten to the first item when it is full
|
||||
Should the buffer is overwritten to the first item when it is full
|
||||
*/
|
||||
/******************************************************************************/
|
||||
Adafruit_FIFO::Adafruit_FIFO(void* buffer, uint16_t depth, uint8_t item_size, bool overwrite)
|
||||
: _buffer( (uint8_t*) buffer), _depth(depth), _item_size(item_size), _overwritable(overwrite)
|
||||
Adafruit_FIFO::Adafruit_FIFO(uint16_t depth, uint8_t item_size, bool overwrite)
|
||||
: _depth(depth), _item_size(item_size), _overwritable(overwrite)
|
||||
{
|
||||
_buffer = (uint8_t*) malloc(item_size*depth); // use malloc_name for debug
|
||||
_count = _wr_idx = _rd_idx = 0;
|
||||
|
||||
_mutex = xSemaphoreCreateMutex();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
* @return
|
||||
*/
|
||||
Adafruit_FIFO::~Adafruit_FIFO()
|
||||
{
|
||||
vSemaphoreDelete(_mutex);
|
||||
free(_buffer); // use free_name for debug
|
||||
}
|
||||
|
||||
bool Adafruit_FIFO::_mutex_lock(bool isr)
|
||||
{
|
||||
(void) isr;
|
||||
@@ -79,7 +89,9 @@ bool Adafruit_FIFO::_mutex_unlock(bool isr)
|
||||
/******************************************************************************/
|
||||
void Adafruit_FIFO::clear(void)
|
||||
{
|
||||
_mutex_lock(false);
|
||||
_rd_idx = _wr_idx = _count = 0;
|
||||
_mutex_unlock(false);
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
@@ -59,7 +59,10 @@ class Adafruit_FIFO
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Adafruit_FIFO(void* buffer, uint16_t depth, uint8_t item_size, bool overwrite);
|
||||
Adafruit_FIFO(uint16_t depth, uint8_t item_size, bool overwrite = false);
|
||||
|
||||
virtual ~Adafruit_FIFO();
|
||||
|
||||
|
||||
void clear(void);
|
||||
bool peek(void* buffer);
|
||||
|
||||
@@ -63,9 +63,9 @@ const uint8_t BLEUART_UUID_CHR_TXD[] =
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
BLEUart::BLEUart(void)
|
||||
BLEUart::BLEUart(uint16_t fifo_depth)
|
||||
: BLEService(BLEUART_UUID_SERVICE), _txd(BLEUART_UUID_CHR_TXD), _rxd(BLEUART_UUID_CHR_RXD),
|
||||
_rxd_fifo(_rxd_buf, sizeof(_rxd_buf), 1, true)
|
||||
_rxd_fifo(fifo_depth, 1)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
#include "BLECharacteristic.h"
|
||||
#include "BLEService.h"
|
||||
|
||||
#define BLE_UART_FIFO_LEN 64
|
||||
#define BLE_UART_DEFAULT_FIFO_DEPTH 256
|
||||
|
||||
class BLEUart : public BLEService, public Stream
|
||||
{
|
||||
@@ -50,11 +50,10 @@ class BLEUart : public BLEService, public Stream
|
||||
BLECharacteristic _txd;
|
||||
BLECharacteristic _rxd;
|
||||
|
||||
uint8_t _rxd_buf[BLE_UART_FIFO_LEN];
|
||||
Adafruit_FIFO _rxd_fifo;
|
||||
|
||||
public:
|
||||
BLEUart(void);
|
||||
BLEUart(uint16_t fifo_depth = BLE_UART_DEFAULT_FIFO_DEPTH);
|
||||
|
||||
virtual err_t start(void);
|
||||
|
||||
|
||||
Reference in new issue
Block a user