Merge pull request #793 from alistair23/alistair/tock

NonArduino: Tock: Fixup some bugs and expand the example
This commit is contained in:
Jan Gromeš 2023-07-11 16:11:05 +02:00 committed by GitHub
commit 9fa8434e47
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 8 deletions

View file

@ -45,8 +45,8 @@ add_executable(${PROJECT_NAME} main.cpp)
# link with RadioLib and libtock-c # link with RadioLib and libtock-c
target_link_libraries(${PROJECT_NAME} PUBLIC target_link_libraries(${PROJECT_NAME} PUBLIC
RadioLib RadioLib
gcc
${CMAKE_CURRENT_SOURCE_DIR}/libtock-c/libtock/build/cortex-m4/libtock.a ${CMAKE_CURRENT_SOURCE_DIR}/libtock-c/libtock/build/cortex-m4/libtock.a
${CMAKE_CURRENT_SOURCE_DIR}/libtock-c/libc++/cortex-m/libgcc.a
${CMAKE_CURRENT_SOURCE_DIR}/libtock-c/libc++/cortex-m/libstdc++.a ${CMAKE_CURRENT_SOURCE_DIR}/libtock-c/libc++/cortex-m/libstdc++.a
${CMAKE_CURRENT_SOURCE_DIR}/libtock-c/newlib/cortex-m/v7-m/libc.a ${CMAKE_CURRENT_SOURCE_DIR}/libtock-c/newlib/cortex-m/v7-m/libc.a
${CMAKE_CURRENT_SOURCE_DIR}/libtock-c/newlib/cortex-m/v7-m/libm.a ${CMAKE_CURRENT_SOURCE_DIR}/libtock-c/newlib/cortex-m/v7-m/libm.a

View file

@ -190,6 +190,10 @@ class TockHal : public RadioLibHal {
void spiEnd() { void spiEnd() {
} }
void yield() {
::yield();
}
private: private:
}; };

View file

@ -32,7 +32,7 @@
// the entry point for the program // the entry point for the program
int main(void) { int main(void) {
printf("[SX1261] Initializing ... \n"); printf("[SX1261] Initialising Radio ... \r\n");
// create a new instance of the HAL class // create a new instance of the HAL class
TockHal* hal = new TockHal(); TockHal* hal = new TockHal();
@ -46,29 +46,32 @@ int main(void) {
Module* tock_module = new Module(hal, RADIO_NSS, RADIO_DIO_1, RADIO_RESET, RADIO_BUSY); Module* tock_module = new Module(hal, RADIO_NSS, RADIO_DIO_1, RADIO_RESET, RADIO_BUSY);
SX1262* radio = new SX1262(tock_module); SX1262* radio = new SX1262(tock_module);
int state = radio->begin(); // Setup the radio
// The settings here work for the SparkFun LoRa Thing Plus - expLoRaBLE
int state = radio->begin(915.0, 125.0, 9, 7, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, 10, 8, 0, false);
if (state != RADIOLIB_ERR_NONE) { if (state != RADIOLIB_ERR_NONE) {
printf("failed, code %d\n", state); printf("failed, code %d\r\n", state);
return 1; return 1;
} }
printf("success!\n"); printf("success!\r\n");
// loop forever // loop forever
for(;;) { for(;;) {
yield_no_wait(); yield_no_wait();
// send a packet // send a packet
printf("[SX1261] Transmitting packet ... \n"); printf("[SX1261] Transmitting '%s' \r\n", transmit_string);
state = radio->transmit("Hello World!"); state = radio->transmit("Hello World!");
if(state == RADIOLIB_ERR_NONE) { if(state == RADIOLIB_ERR_NONE) {
// the packet was successfully transmitted // the packet was successfully transmitted
printf("success!\n"); printf("success!\r\n");
// wait for a second before transmitting again // wait for a second before transmitting again
hal->delay(1000); hal->delay(1000);
} else { } else {
printf("failed, code %d\n", state); printf("failed, code %d\r\n", state);
} }
} }