mbed support for STM32F103C8T6 (Blue Pill) boards
Revision 15:e694fb54a079, committed 2018-09-30
- Comitter:
- faydrus
- Date:
- Sun Sep 30 02:47:49 2018 +0000
- Parent:
- 14:900adc64ed43
- Commit message:
- Refactored function prototypes and externs
Changed in this revision
--- a/at_commands.cpp Fri Sep 28 13:28:09 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,157 +0,0 @@ -#include <ATCmdParser.h> - - -// The AT command parser for the serial interface. - - -// AT commands we'd like to have: -// -// AT+Freq? -- get the frequency -// -- <value> -- current frequency -// -// AT+Freq -- set the frequency -// -- OK -- response -// <data> -- frequency value -// -- OK -- response -// -// AT+SF? -- get the spreading factor -// -- <value> -- current spreading factor -// -// AT+SF -- set the spreading factor -// -- OK -- response -// <value> -- spreading factor -// -- OK -- response -// -// AT+BW? -- get the bandwidth -// -- <value> -- current bandwidth -// -// AT+BW -- set the bandwidth -// -- OK -- response -// <value> -- bandwidth value -// -- OK -- response -// -// AT+RXDEQ? -- Dequeue the RX queue -// -- <value> -- RX frame -// -// AT+RXCNT? -- get the number of RX frames waiting in the queue -// -- <value> -- number of RX frames -// -// AT+RXCLR -- clear the RX queue -// -- OK -- response -// -// AT+TXENQ -- Load the TX queue with another frame -// -- OK -- response -// <data> -- TX frame data -// -- OK -- response -// -// AT+TXCNT? -- get the number of TX frames waiting in the queue -// -- <value> -- number of TX frames -// -// AT+TXCLR -- clear the TX queue -// -- OK -- response -// -// AT+NVS -- save settings to Non-Volatile Storage (NVS) -// -- OK -- response -// -// - -char response[64]; -char recv_data[256]; -#if 0 -void processATCmds(ATCmdParser *at) { - at->recv("AT+%s", response); - if(!strcmp(response, "Freq?")) { - at->send(radio->freq); - } - else if(!strcmp(response, "Freq")) { - at->send("OK"); - int32_t new_freq; - at->recv("%d", new_freq); - if(new_freq > 450000000 || new_freq < 420000000) { - at->send("ERR OUT_OF_RANGE"); - } - else { - radio->freq = new_freq; - at->send("OK"); - } - } - else if(!strcmp(response, "SF?")) { - at->send(radio->sf); - } - else if(!strcmp(response, "SF")) { - at->send("OK"); - int32_t new_sf; - at->recv("%d", new_sf); - if(new_sf < 6 || new_sf > 12) { - at->send("ERR INVALID"); - } - else { - radio->sf = new_sf; - at->send("OK"); - } - } - else if(!strcmp(response, "BW?")) { - at->send(radio->bw); - } - else if(!strcmp(response, "BW")) { - at->send("OK"); - int32_t new_bw; - at->recv("%d", new_bw); - if(new_bw == 125000 || new_bw == 250000 || new_bw == 500000) { - radio->bw = new_bw; - at->send("OK"); - } - else { - at->send("ERR INVALID"); - } - } - else if(!strcmp(response, "RXDEQ?")) { - int errcode = rx_queue->dequeue(); - if(!errcode) { - at->send(rx_queue->dequeue()); - } - else { - at->send("ERR %d", errcode); - } - } - else if(!strcmp(response, "RXCNT?")) { - at->send(rx_queue->getCount()); - } - else if(!strcmp(response, "RXCLR")) { - tx_queue->clear(); - at->send("OK"); - } - else if(!strcmp(response, "TXENQ")) { - at->send("OK"); - at->recv("%s", recv_data); - int errcode = tx_queue->enqueue(recv_data); - if(!errcode) { - at->send("OK"); - } - else { - at->send("ERR %d", errcode); - } - } - else if(!strcmp(response, "TXCNT?")) { - at->send(tx_queue->getSize()); - } - else if(!strcmp(response, "TXCLR")) { - int errcode = tx_queue->clear(); - if(!errcode) { - at->send("OK"); - else { - at->send("ERR %d", errcode); - } - } - else if(!strcmp(response, "NVS")) { - int errcode = nv_settings->save(); - if(!errcode) { - at->send("OK"); - } - else { - at->send("ERR %d", errcode); - } - } -} - -#endif
--- a/peripherals/lora_radio.cpp Fri Sep 28 13:28:09 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -#include "mbed.h" -#include "CircularBuffer.h" -#include "sx1276-hal.h" - - -static void TxDoneCb(void) {}; -static void TxTimeoutCb(void) {}; -static void RxDoneCb(uint8_t *pld, uint16_t size, int16_t rssi, int8_t snr); -static void RxTimeoutCb(void) {}; -static void RxErrorCb(void) {}; -static void FhssChangeChannelCb(uint8_t currentChannel) {}; -static void CadDoneCb(bool ChannelActivityDetected) {}; - - -SX1276MB1xAS Radio( NULL ); - -void initLoRaRadio() { - // Set up the RadioEvents - static RadioEvents_t events; - events.TxDone = TxDoneCb; - events.TxTimeout = TxTimeoutCb; - events.RxDone = RxDoneCb; - events.RxTimeout = RxTimeoutCb; - events.RxError = RxErrorCb; - events.FhssChangeChannel = FhssChangeChannelCb; - events.CadDone = CadDoneCb; - - Radio.Init(&events); -} - -typedef struct { - uint8_t pld[128]; -} pkt_t; -CircularBuffer<pkt_t, 32, uint32_t> rx_plds; -CircularBuffer<uint16_t, 32, uint32_t> rssi_vals; -CircularBuffer<uint16_t, 32, uint32_t> snr_vals; -static pkt_t mesh_pkt; -static void RxDoneCb(uint8_t *pld, uint16_t size, int16_t rssi, int8_t snr) { - static pkt_t tmp_pld; - memcpy((void *) &tmp_pld, (void *) pld, size); - memcpy((void *) &mesh_pkt, (void *) pld, size); - rx_plds.push(tmp_pld); - rssi_vals.push(rssi); - snr_vals.push(snr); -} \ No newline at end of file
--- a/peripherals/nv_settings.cpp Fri Sep 28 13:28:09 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,41 +0,0 @@ -#include "mbed.h" - -#define EEPROM_INIT_WORD 0xDEADBEEF -typedef struct { - uint32_t init_word; - uint32_t freq; - uint8_t sf; - uint32_t bw; - uint8_t cr; - int8_t pow; -} nv_cfg_t; - - -#define NV_FLASH_BASEADDR 0x8001E000 -static FlashIAP flash_iap; -static nv_cfg_t nv_cfg; -nv_cfg_t *readNVCfg(void) { - flash_iap.read((void *) &nv_cfg, NV_FLASH_BASEADDR, sizeof(nv_cfg_t)); - return &nv_cfg; -} - - -void writeNVCfg(nv_cfg_t *new_nv_cfg) { - uint32_t sector_size = flash_iap.get_sector_size(NV_FLASH_BASEADDR); - flash_iap.erase(NV_FLASH_BASEADDR, sector_size); - flash_iap.program((void *) new_nv_cfg, NV_FLASH_BASEADDR, sector_size); -} - - -void initNVCfg(void) { - nv_cfg_t *nv_cfg = readNVCfg(); - if(nv_cfg->init_word != EEPROM_INIT_WORD) { - nv_cfg->init_word = EEPROM_INIT_WORD; - nv_cfg->freq = 433000000; - nv_cfg->sf = 12; - nv_cfg->bw = 500000; - nv_cfg->cr = 1; - nv_cfg->pow = 14; - } - writeNVCfg(nv_cfg); -}
--- a/peripherals/oled.cpp Fri Sep 28 13:28:09 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,35 +0,0 @@ -#include "mbed.h" -#include "Adafruit_SSD1306.h" - -I2C *i2c_oled; -Adafruit_SSD1306_I2c *oled_disp; - -void initOLED(void) { - i2c_oled = new I2C(PB_9, PB_8); - oled_disp = new Adafruit_SSD1306_I2c(*i2c_oled, PB_7); -} - -void testOLED(void) { - oled_disp->clearDisplay(); - oled_disp->splash(); - oled_disp->display(); - oled_disp->clearDisplay(); - oled_disp->splash(); - oled_disp->display(); - wait(2.0); - oled_disp->clearDisplay(); - oled_disp->display(); - oled_disp->setTextCursor(0,8); - oled_disp->printf("Hello, world!"); - oled_disp->setTextCursor(0,16); - oled_disp->printf("--------"); - oled_disp->setTextCursor(0,24); - oled_disp->printf("Goodbye!"); - oled_disp->display(); - wait(1.0); - oled_disp->clearDisplay(); - oled_disp->display(); - oled_disp->setTextCursor(0,8); - oled_disp->printf("OLED TESTING COMPLETE"); - oled_disp->display(); -} \ No newline at end of file
--- a/peripherals/peripherals.hpp Fri Sep 28 13:28:09 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ -#ifndef PERIPHERALS_HPP -#define PERIPHERALS_HPP - -// OLED display functions -void initOLED(void) -void testOLED(void); - - - - -#endif /* PERIPHERALS_HPP */ \ No newline at end of file
--- a/peripherals/pkt_leds.cpp Fri Sep 28 13:28:09 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,61 +0,0 @@ -// Toggle a LED -#include "mbed.h" - -DigitalOut rx_led(PB_12); -DigitalOut tx_led(PB_13); -DigitalOut hop0_led(PB_11); -DigitalOut hop1_led(PB_10); -DigitalOut hop2_led(PB_1); -DigitalOut hop3_led(PB_0); - -DigitalOut main_led(PC_13); - -void testLEDs(void) { - for(int i = 0; i < 4; i++) { - rx_led = !rx_led; - wait(0.2); - tx_led = !tx_led; - wait(0.2); - hop0_led = !hop0_led; - wait(0.2); - hop1_led = !hop1_led; - wait(0.2); - hop2_led = !hop2_led; - wait(0.2); - hop3_led = !hop3_led; - wait(0.2); - } - rx_led = 0; - tx_led = 0; - hop0_led = 0; - hop1_led = 0; - hop2_led = 0; - hop3_led = 0; -} - - -void blinkMainLED(void) { - main_led = !main_led; -} - - -static Timeout main_led_timeout; -static bool blink_main_led = false; -void mainLEDTimeout(void) { - blink_main_led = true; - main_led_timeout.attach(&mainLEDTimeout, 0.5); -} - - -void initEventLEDs(void) { - main_led_timeout.attach(&mainLEDTimeout, 0.5); -} - - -// Event loop function for the LEDs -void eventLEDs(void) { - if(blink_main_led) { - blinkMainLED(); - blink_main_led = false; - } -}
--- a/pseudo_rtos/event_loop.cpp Fri Sep 28 13:28:09 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,9 +0,0 @@ -#include "mbed.h" - -// Our main event loop. Used in lieu of a real RTOS. -extern void eventLEDs(void); -void eventLoop(void) { - while(true) { - eventLEDs(); - } -} \ No newline at end of file