Skip to content

Commit

Permalink
Change USB C touch to use same nets as Somu, remove nfc_peripheral_ex…
Browse files Browse the repository at this point in the history
…ists.
  • Loading branch information
emosenkis committed Dec 3, 2019
1 parent d7046dc commit 76b5c9b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 28 deletions.
5 changes: 1 addition & 4 deletions targets/stm32l432/src/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,7 @@ void device_init()

hw_init(LOW_FREQUENCY);

if (nfc_peripheral_exists())
{
_NFC_status = nfc_init();
}
_NFC_status = nfc_init();

if (_NFC_status == NFC_IS_ACTIVE)
{
Expand Down
39 changes: 16 additions & 23 deletions targets/stm32l432/src/sense.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,53 +6,47 @@
#include "stm32l4xx_hal_tsc.h"

/**
USB A Nano TSC GPIO Configuration:
USB A Nano & USB C Touch TSC GPIO Configuration:
PB4 ------> Channel 1 (electrode 1)
PB5 ------> Channel 2 (electrode 2)
PB6 ------> Channel 3 (sampling capacitor)
PB7 ------> Channel 4 (unused)
USB C Touch TSC GPIO Configuration
PB4 ------> Channel 1 (sampling cap)
PB5 ------> Channel 2 (electrode 2)
PB6 ------> Channel 3 (unused)
PB7 ------> Channel 4 (electrode 1)
*/
int get_sampling_cap_io(void)
inline int get_sampling_cap_io(void)
{
return nfc_peripheral_exists() ? TSC_GROUP2_IO1 : TSC_GROUP2_IO3;
return TSC_GROUP2_IO3;
}

int get_sampling_cap_pin(void)
inline int get_sampling_cap_pin(void)
{
return nfc_peripheral_exists() ? LL_GPIO_PIN_4 : LL_GPIO_PIN_6;
return LL_GPIO_PIN_6;
}

int get_first_electrode_io(void)
inline int get_first_electrode_io(void)
{
return nfc_peripheral_exists() ? TSC_GROUP2_IO4 : TSC_GROUP2_IO1;
return TSC_GROUP2_IO1;
}

int get_first_electrode_pin(void)
inline int get_first_electrode_pin(void)
{
return nfc_peripheral_exists() ? LL_GPIO_PIN_7 : LL_GPIO_PIN_4;
return LL_GPIO_PIN_4;
}

int get_second_electrode_io(void)
inline int get_second_electrode_io(void)
{
return TSC_GROUP2_IO2;
}

int get_second_electrode_pin(void)
inline int get_second_electrode_pin(void)
{
return LL_GPIO_PIN_5;
}

int get_tsc_threshold(void)
int unsigned get_tsc_threshold(void)
{
// Threshold for USB A nano is 45
// Threshold for USB C touch is not yet calibrated so this is a dummy value
return nfc_peripheral_exists() ? 59 : 45;
return has_10nF_sampling_cap() ? 59 : 45;
}

void tsc_init(void)
Expand Down Expand Up @@ -161,7 +155,7 @@ uint32_t tsc_read_button(uint32_t index)
#define PIN_SHORTED_YES 1
#define PIN_SHORTED_NO 2

int pin_grounded(int bank, int pin_mask) {
int pin_grounded(GPIO_TypeDef* bank, int pin_mask) {
LL_GPIO_SetPinMode(bank, (pin_mask), LL_GPIO_MODE_INPUT);
LL_GPIO_SetPinPull(bank, (pin_mask), LL_GPIO_PULL_UP);

Expand All @@ -183,10 +177,9 @@ int tsc_sensor_exists(void)
return does == PIN_SHORTED_YES;
}

int nfc_peripheral_exists(void)
int has_10nF_sampling_cap(void)
{
// USB A & USB C don't have TSC sensors and do support NFC
if (!tsc_sensor_exists()) return 1;
if (!tsc_sensor_exists()) return 0;
// Must be either USB A nano or USB C touch. PA8 is only grounded in USB C touch.
static uint8_t does = PIN_SHORTED_UNDEF;
if (does == PIN_SHORTED_UNDEF) does = pin_grounded(GPIOA, LL_GPIO_PIN_8);
Expand Down
2 changes: 1 addition & 1 deletion targets/stm32l432/src/sense.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
void tsc_init(void);

int tsc_sensor_exists(void);
int nfc_peripheral_exists(void);
int has_10nF_sampling_cap(void);

// Read button0 or button1
// Returns 1 if pressed, 0 if not.
Expand Down

0 comments on commit 76b5c9b

Please sign in to comment.