Skip to content

Commit

Permalink
SPISettings managements
Browse files Browse the repository at this point in the history
Signed-off-by: Frederic Pillon <[email protected]>
  • Loading branch information
fpistm committed Feb 17, 2020
1 parent c4f359a commit 02ff3a6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
19 changes: 9 additions & 10 deletions src/utility/HCISpiTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@

volatile int data_avail = 0;

HCISpiTransportClass::HCISpiTransportClass(SPIClass& spi, BLEChip_t ble_chip, uint8_t cs_pin, uint8_t spi_irq, uint8_t ble_rst, unsigned long frequency, int spi_mode) :
HCISpiTransportClass::HCISpiTransportClass(SPIClass& spi, BLEChip_t ble_chip, uint8_t cs_pin, uint8_t spi_irq, uint8_t ble_rst, uint32_t frequency, uint8_t spi_mode) :
_spi(&spi),
_ble_chip(ble_chip),
_cs_pin(cs_pin),
_spi_irq(spi_irq),
_ble_rst(ble_rst),
_frequency(frequency),
_spi_mode(spi_mode)
_ble_rst(ble_rst)
{
_spiSettings = SPISettings(frequency, (BitOrder)BLE_SPI_BYTE_ORDER, spi_mode);
_read_index = 0;
_write_index = 0;
_write_index_initial = 0;
Expand Down Expand Up @@ -125,7 +124,7 @@ int HCISpiTransportClass::available()
detachInterrupt(_spi_irq);
}

_spi->beginTransaction(SPISettings(_frequency, MSBFIRST, _spi_mode));
_spi->beginTransaction(_spiSettings);

digitalWrite(_cs_pin, LOW);

Expand Down Expand Up @@ -337,7 +336,7 @@ size_t HCISpiTransportClass::write(const uint8_t* data, size_t length)
{
result = 0;

_spi->beginTransaction(SPISettings(_frequency, MSBFIRST, _spi_mode));
_spi->beginTransaction(_spiSettings);

digitalWrite(_cs_pin, LOW);

Expand Down Expand Up @@ -376,7 +375,7 @@ size_t HCISpiTransportClass::write(const uint8_t* data, size_t length)

detachInterrupt(_spi_irq);

_spi->beginTransaction(SPISettings(_frequency, MSBFIRST, _spi_mode));
_spi->beginTransaction(_spiSettings);

digitalWrite(_cs_pin, LOW);

Expand Down Expand Up @@ -458,7 +457,7 @@ void HCISpiTransportClass::wait_for_blue_initialize()
{
uint8_t header_master[5] = {0x0b, 0x00, 0x00, 0x00, 0x00};

_spi->beginTransaction(SPISettings(_frequency, MSBFIRST, _spi_mode));
_spi->beginTransaction(_spiSettings);

digitalWrite(_cs_pin, LOW);

Expand Down Expand Up @@ -526,7 +525,7 @@ void HCISpiTransportClass::wait_for_enable_ll_only()
{
uint8_t header_master[5] = {0x0b, 0x00, 0x00, 0x00, 0x00};

_spi->beginTransaction(SPISettings(_frequency, MSBFIRST, _spi_mode));
_spi->beginTransaction(_spiSettings);

digitalWrite(_cs_pin, LOW);

Expand Down Expand Up @@ -580,7 +579,7 @@ void HCISpiTransportClass::enable_ll_only()
{
result = 0;

_spi->beginTransaction(SPISettings(_frequency, MSBFIRST, _spi_mode));
_spi->beginTransaction(_spiSettings);

digitalWrite(_cs_pin, LOW);

Expand Down
8 changes: 5 additions & 3 deletions src/utility/HCISpiTransport.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@ typedef enum BLEChip_s {
BLUENRG_M2SP
} BLEChip_t;

#ifndef BLE_SPI_BYTE_ORDER
#define BLE_SPI_BYTE_ORDER MSBFIRST
#endif
#define BLE_MODULE_SPI_BUFFER_SIZE 128

class HCISpiTransportClass : public HCITransportInterface {
public:
HCISpiTransportClass(SPIClass& spi, BLEChip_t ble_chip, uint8_t cs_pin, uint8_t spi_irq, uint8_t ble_rst, unsigned long frequency, int spi_mode);
HCISpiTransportClass(SPIClass& spi, BLEChip_t ble_chip, uint8_t cs_pin, uint8_t spi_irq, uint8_t ble_rst, uint32_t frequency, uint8_t spi_mode);
virtual ~HCISpiTransportClass();

virtual int begin();
Expand All @@ -52,12 +55,11 @@ class HCISpiTransportClass : public HCITransportInterface {
void wait_for_enable_ll_only();
void enable_ll_only();
SPIClass* _spi;
SPISettings _spiSettings;
BLEChip_t _ble_chip;
uint8_t _cs_pin;
uint8_t _spi_irq;
uint8_t _ble_rst;
unsigned long _frequency;
int _spi_mode;
uint8_t _rxbuff[BLE_MODULE_SPI_BUFFER_SIZE];
uint16_t _read_index;
uint16_t _write_index;
Expand Down

0 comments on commit 02ff3a6

Please sign in to comment.