From a8c06882d268a3b3fcb5f3d7620f776515dfcf66 Mon Sep 17 00:00:00 2001 From: Pete Schwamb Date: Fri, 17 Nov 2017 11:33:17 -0800 Subject: [PATCH 1/4] single-response protocol updates --- firmware/ble113_rfspy/gatt.xml | 2 +- firmware/ble113_rfspy/main.bgs | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/firmware/ble113_rfspy/gatt.xml b/firmware/ble113_rfspy/gatt.xml index dc7e450..062a312 100644 --- a/firmware/ble113_rfspy/gatt.xml +++ b/firmware/ble113_rfspy/gatt.xml @@ -48,7 +48,7 @@ Version - ble_rfspy 0.9 + ble_rfspy 2.0 LED Mode diff --git a/firmware/ble113_rfspy/main.bgs b/firmware/ble113_rfspy/main.bgs index 7b6a370..030dbc9 100644 --- a/firmware/ble113_rfspy/main.bgs +++ b/firmware/ble113_rfspy/main.bgs @@ -94,6 +94,10 @@ procedure set_led_mode(value) end procedure do_spi() + if in_spi = 1 then + return + end if + in_spi = 1 call hardware_io_port_write(0, $10, 0) @@ -159,7 +163,7 @@ event attributes_value(connection, reason, handle, offset, value_len, value_data # Write to SPI if finished if offset + value_len = expected_length then spi_out_buf_len = expected_length - if waiting_for_client != 1 && in_spi = 0 + if waiting_for_client != 1 call do_spi() end if end if @@ -200,9 +204,9 @@ event attributes_user_read_request(connection, handle, offset, maxsize) if waiting_for_client = 0 call set_data_led(0) + call do_spi() end if - end if if handle = xgatt_led_mode then @@ -240,7 +244,7 @@ end # Timer event listener to poll data from spi event hardware_soft_timer(handle) - if waiting_for_client != 1 && in_spi = 0 + if waiting_for_client != 1 call do_spi() end if From 7eb8176604a4c253dedbf85d673e0b53426be4cf Mon Sep 17 00:00:00 2001 From: Pete Schwamb Date: Sat, 10 Feb 2018 11:36:17 -0800 Subject: [PATCH 2/4] Only drive SPI while ble client connected --- firmware/ble113_rfspy/main.bgs | 5 +- .../ble113_rfspy/variable_memory_usage.txt | 49 ++++++++++--------- 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/firmware/ble113_rfspy/main.bgs b/firmware/ble113_rfspy/main.bgs index 030dbc9..f362540 100644 --- a/firmware/ble113_rfspy/main.bgs +++ b/firmware/ble113_rfspy/main.bgs @@ -8,6 +8,7 @@ dim spi_out_buf_len # 1 = waiting for ble client to read bytes from data attr. # We halt spi comms until this happens. Crude flow control. dim waiting_for_client +dim connected dim slave_bytes_avail dim spi_xfer_size dim spi_batch_size @@ -244,7 +245,7 @@ end # Timer event listener to poll data from spi event hardware_soft_timer(handle) - if waiting_for_client != 1 + if waiting_for_client != 1 && connected = 1 then call do_spi() end if @@ -262,6 +263,7 @@ end event connection_status(connection, flags, address, address_type, conn_interval, timeout, latency, bonding) # Device is connected. Turn on green led call hardware_io_port_write(0, $1, $1) + connected = 1 # Drop any data what was waiting to go to client from # previous connection. @@ -276,6 +278,7 @@ event connection_disconnected(handle,res) call gap_set_mode(gap_general_discoverable,gap_undirected_connectable) # Device disconnected. Turn off green led call hardware_io_port_write(0, $1, $0) + connected = 0 # Save name if name_len > 0 diff --git a/firmware/ble113_rfspy/variable_memory_usage.txt b/firmware/ble113_rfspy/variable_memory_usage.txt index e0364a4..7fc2b9b 100644 --- a/firmware/ble113_rfspy/variable_memory_usage.txt +++ b/firmware/ble113_rfspy/variable_memory_usage.txt @@ -1,4 +1,4 @@ -644 +648 0:0 GAP_AD_FLAG_BREDR_NOT_SUPPORTED 0:0 GAP_AD_FLAG_GENERAL_DISCOVERABLE 0:0 GAP_AD_FLAG_LIMITED_DISCOVERABLE @@ -89,26 +89,27 @@ 261:255 spi_out_buf 516:4 spi_out_buf_len 520:4 waiting_for_client -524:4 slave_bytes_avail -528:4 spi_xfer_size -532:4 spi_batch_size -536:4 spi_batch_offset -540:32 name -572:4 name_len -576:4 result -580:4 channel -584:4 continue -588:4 escaping -592:4 bytes_to_send -596:4 tlen -600:4 idx -604:4 response_count -608:4 expected_length -612:4 send_idx -616:4 chunk_size -620:4 in_spi -624:4 timer_tick_count -628:4 timer_update_count -632:4 led_mode -636:4 batconn_handle -640:4 batresult +524:4 connected +528:4 slave_bytes_avail +532:4 spi_xfer_size +536:4 spi_batch_size +540:4 spi_batch_offset +544:32 name +576:4 name_len +580:4 result +584:4 channel +588:4 continue +592:4 escaping +596:4 bytes_to_send +600:4 tlen +604:4 idx +608:4 response_count +612:4 expected_length +616:4 send_idx +620:4 chunk_size +624:4 in_spi +628:4 timer_tick_count +632:4 timer_update_count +636:4 led_mode +640:4 batconn_handle +644:4 batresult From 81a091f808a0b80dc3957eda22189ce62d1baa9b Mon Sep 17 00:00:00 2001 From: Pete Schwamb Date: Tue, 10 Apr 2018 17:11:59 -0700 Subject: [PATCH 3/4] Clear ble output buffer on receipt of new ble command --- firmware/ble113_rfspy/main.bgs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/firmware/ble113_rfspy/main.bgs b/firmware/ble113_rfspy/main.bgs index f362540..39e0a3d 100644 --- a/firmware/ble113_rfspy/main.bgs +++ b/firmware/ble113_rfspy/main.bgs @@ -42,7 +42,7 @@ event system_boot(major,minor,patch,build,ll_version,protocol,hw) name_len=0 response_count=0 in_spi=0 - led_mode=0 + led_mode=1 call flash_ps_load($8000)(result, name_len, name(0:name_len)) if result != 0 then @@ -158,6 +158,7 @@ event attributes_value(connection, reason, handle, offset, value_len, value_data if handle = xgatt_data then if offset = 0 then expected_length = value_data(0:1) + 1 + waiting_for_client = 0 end if spi_out_buf(offset:value_len) = value_data(0:value_len) From f1dd01c826f6bb83e9f73075b46f3a47c287acc1 Mon Sep 17 00:00:00 2001 From: Pete Schwamb Date: Tue, 22 May 2018 20:43:17 -0700 Subject: [PATCH 4/4] Change led mode to off by default --- firmware/ble113_rfspy/main.bgs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/ble113_rfspy/main.bgs b/firmware/ble113_rfspy/main.bgs index 39e0a3d..4b28bee 100644 --- a/firmware/ble113_rfspy/main.bgs +++ b/firmware/ble113_rfspy/main.bgs @@ -42,7 +42,7 @@ event system_boot(major,minor,patch,build,ll_version,protocol,hw) name_len=0 response_count=0 in_spi=0 - led_mode=1 + led_mode=0 call flash_ps_load($8000)(result, name_len, name(0:name_len)) if result != 0 then