In this post, I will take you through the PRoC BLE schematic and firmware. I describe a very similar version to this in great detail in the video you can find on the Cypress Video Training website.
First, I create a new project in my workspace called “145capsenseled-ble.” Then, I add the UART component (the SCB version) and the BLE component.
Next, I configure the component to be a GATT server with a custom profile and a GAP client.
Then I create a custom service with two characteristics:
- The “led” characteristic, which is set up as a uint8 that is writeable and readable.
- The “capsense” characteristic, which is set up as uint16 that is readable and has a “notify.”
Next, I configure the UUIDs of the service and characteristics to match what is hard-coded in the iOS app. Then, I add “Client User Descriptions” that describe the characteristics in plain text.
Next I configure the GAP settings, specifically the advertising packet.
I make the pin I assignments, which is just the UART Rx and Tx lines.
Finally, I write the firmware. I started with main. In the infinite loop (line 116), if I have received a byte from other side, then I assign it to the global variable “fingerPos” (line 118). Next, call updateCapsense() (line 119), to update the GATT database with the new value of the slider.
The updateCapsense function:
Lines 31/32 If there is no connection, then don’t update the GATT database.
Lines 33-39 Update the GATT database with the current fingerPosition.
Lines 42-43 If the iPhone side has asked for notification and the position has changed, then send a notification.
Line 44 Save the last position.
The BleCallBack is the most complicated section of firmware. It uses a “switch” statement to handle the different event “cases.” The cases are:
- CYBLE_EVT_STACK_ON & CYBLE_EVT_GAP_DEVICE_DISCONNECTED: In either of these cases you want to start the advertising function.
- CYBLE_EVT_GATT_CONNECT_IND: When there is a connection made, update the GATT database with the current state of the CapSense and the LED. This allows the iOS side to read the correct values.
- CYBLE_EVT_WRITE_REQ: There are two kinds of write requests that are valid.
- CYBLE_LED_CAPSENSE_LED_CHAR_HANDLE: If the remote side writes into the LED value, then send that data to the PSoC4000S via the UART.
- CYBLE_LEDCAPSENSE_CAPSENSE_CAPSENSECCCD: If the remote side has been asked to notify (or un-notify), then save that in the global variable capsenseNotify.
That is all of the firmware.
In the next post, I’ll take you through the debugging I had to do.
You can find the PSoC Creator workspace on github in the directory called “capsenseble-145.”
PSoC4000s and the CY8CKIT145 Stamp Board - Part 1
The board and schematics
PSoC4000s and the CY8CKIT145 Stamp Board - Part 2
PSoC4000s and the CY8CKIT145 Stamp Board - Part 3
PRoC BLE Firmware
PSoC4000s and the CY8CKIT145 Stamp Board - Part 4
Debugging the problem