diff --git a/README.md b/README.md index ace874f..4ced2c1 100644 --- a/README.md +++ b/README.md @@ -65,3 +65,13 @@ command: ``` sudo openocd -f interface/ftdi/digilent-hs1.cfg -f interface/ftdi/swd-resistor-hack.cfg -f target/stm32l1.cfg -c "init" -c "reset init" -c "program build/lora.irr.elf verify reset exit" ``` + +Pins +---- + +The [pinout guide for the Node151](http://resource.heltec.cn/download/LoRa_Node_151/LoRa_Node_151_Pinout_Diagram.pdf). + +The pins PB5-7,9 are used as active low controls for the relays. + +The pin PB15 is used as an analog input for an RNG source. This pin +should be grounded. diff --git a/board.c b/board.c index 5823738..136d592 100644 --- a/board.c +++ b/board.c @@ -195,7 +195,7 @@ void BoardInitMcu( void ) MX_USB_DEVICE_Init(); - AdcInit( &Adc, NC ); // Just initialize ADC + AdcInit( &Adc, PB_15 ); // Just initialize ADC #if defined( SX1261MBXBAS ) || defined( SX1262MBXCAS ) || defined( SX1262MBXDAS ) SpiInit( &SX126x.Spi, SPI_1, RADIO_MOSI, RADIO_MISO, RADIO_SCLK, NC ); diff --git a/loramac/src/boards/board.h b/loramac/src/boards/board.h index 5bd8914..14e3336 100644 --- a/loramac/src/boards/board.h +++ b/loramac/src/boards/board.h @@ -23,6 +23,8 @@ #ifndef __BOARD_H__ #define __BOARD_H__ +#include + #ifdef __cplusplus extern "C" { @@ -125,6 +127,8 @@ uint8_t GetBoardPowerSource( void ); */ Version_t BoardGetVersion( void ); +extern Adc_t Adc; + #ifdef __cplusplus } #endif diff --git a/main.c b/main.c index 6984274..2ff4fb2 100644 --- a/main.c +++ b/main.c @@ -26,15 +26,19 @@ #include -#include - #include +/* LoRaMac headers */ #include -#include +#include #include #include +/* lora-irr headers */ +#include +#include + + char * findeol(char *pos, size_t len) { @@ -202,6 +206,27 @@ radio_seed_rng(void) #endif } +static void +analog_seed_rng(void) +{ +#if 1 + uint16_t v; + int i; + + for (i = 0; i < 256 / 2; i++) { + /* + * Capture some ADC data. If pin is floating, 0xfff + * happens frequently, if pin is grounded, 0 happens + * frequently, filter these values out. + */ + do { + v = AdcReadChannel(&Adc, ADC_CHANNEL_21); + } while (v == 0 || v == 0xfff); + strobe_seed_prng((uint8_t *)&v, sizeof v); + } +#endif +} + int main(void) { @@ -213,6 +238,8 @@ main(void) Radio.Init(&revents); + analog_seed_rng(); + radio_seed_rng(); strobe_rng_save();