The capacitive touch slider deserves a log all to itself. I've never used one before, but i added the parts to the board anyways in hopes that it would work. The CPT112 communicates over I2C which i am familiar with, so i figured i could get it working.
The device can be set up to control 12 buttons, or one touch slider. When an action is detected, the I2C interrupt pin is pulled low. This is connected as an input to the micro-controller, which has an interrupt set up on that pin. When the MCU detects a high->low transition, it knows that the CPT112 has some data to send, so it initiates a read.
The data packet for the slider is a 4 byte value which includes a counter, and event code, an LSB and an MSB for the sider position. So you have to I2C read 4 bytes, and then decode the packet in firmware.
You program the settings of the touch controller using a silicon labs debug adapter and the Simplicity Studio IDE. The settings you need depend on the layout of the touch slider, so there isn't exactly ideal settings that you just set an forget. It took a bit of trial and error to get it to settings that felt smooth.
There were a few gotcha's along the way that took some debugging to figure out.
- At first when i was playing around with the settings, I had the MCU communicating with the CPT112, and also had the debug adapter plugged in for programming and debugging using the DIE. This was a problem because of the interrupt driven nature of the device. When motion is detected, the interrupt pin is driven low, which flags the MCU to read the packet. WIth the debug adapter plugged in, the debug adapter also tried to read the packet, so it became a race. The packet reads are destructive, so it can only be read once. I wasn't getting good performance in my application, and I wasn't getting good data through the Silicon Labs IDE. So to optimize the settings, I disabled the MCU firmware, and used the Simplicity Studio IDE to get the settings correct. Then i disconnected the debug adapter, and enabled my firmware to test it out in the application.
- BLE offers two ways to communicate with a client (the mobile device), Notifications and Indications. When using indications, the client acknowledges back to the BLE device that data was received. When using notifications, there is no acknowledgment. Thus, notifications are much faster. I had been using indications for all of my data transfer, such as when a button is pressed, the push buttons don't need fast data transfer. The touch slider however, does need fast data transfer. If you move your finger along the slider, it creates events at a very fast rate, as fast as every few ms. This rate is too fast to use indications. I realized that there was a bottleneck when using indications, so i had to change the data transfer method to notifications.
- There is also a potential bottleneck in the BLE connection interval. As stated before, i had set it to a fairly slow speed (every 50ms or so). This was fast enough to process button presses. This isn't fast enough to process the touch slider however, so i had to change the connection interval to the minimum (7.5ms). This was mentioned in my 'to-do list' log. This fast connection interval is only needed when the touch slider is being touched, and can be changed back to 50ms when it is not being touched to save power.
Now that I had the CPT112 settings configured, and it communicating properly and quickly with the BGM111, i had to decide on what data to send back to the mobile device. I wanted the MCU to do most of the processing, again for speed reasons. The CPT112 only tells you the position of where your finger is on the slider (a number between 0 and 100). So it is up to the firmware to process numerous reads into relevant information. I figured the relevant information would be the position of the finger when the slider is touched, the position of the finger when the slider is released, the speed of the finger slide, and the direction of the slide. These values are all calculated by the firmware, and then sent to the mobile device using a notification.
All in all, the slider works just OK so far. its not as smooth as i would like it to be. And there seem to be some dead spots, which i presume are because of the slider layout. I was happy to get it working decently though for the first prototype.