Convert macros for controlling test LEDs to functions

This commit is contained in:
Eric Tang
2018-06-24 20:34:23 -07:00
parent 0155447c6a
commit c6b180b8f5
8 changed files with 40 additions and 14 deletions

View File

@@ -21,7 +21,7 @@ void RunWatchdog(void)
cntr++; cntr++;
if (cntr==100) { /* we get called from KEY_SCANNER_HANDLER() which runs at 1ms, thus scaling down by 100 here to get 100 ms period */ if (cntr==100) { /* we get called from KEY_SCANNER_HANDLER() which runs at 1ms, thus scaling down by 100 here to get 100 ms period */
cntr=0; cntr=0;
TEST_LED_TOGGLE(); TestLed_Toggle();
I2cWatchdog_WatchCounter++; I2cWatchdog_WatchCounter++;
if (I2cWatchdog_WatchCounter>10) { /* do not check within the first 1000 ms, as I2C might not be running yet */ if (I2cWatchdog_WatchCounter>10) { /* do not check within the first 1000 ms, as I2C might not be running yet */

View File

@@ -42,7 +42,7 @@ void SlaveRxHandler(void)
case SlaveCommand_SetTestLed: case SlaveCommand_SetTestLed:
TxMessage.length = 0; TxMessage.length = 0;
bool isLedOn = RxMessage.data[1]; bool isLedOn = RxMessage.data[1];
TEST_LED_SET(isLedOn); TestLed_Set(isLedOn);
break; break;
case SlaveCommand_SetLedPwmBrightness: case SlaveCommand_SetLedPwmBrightness:
TxMessage.length = 0; TxMessage.length = 0;

View File

@@ -6,5 +6,5 @@ extern void TestLed_Init(void)
CLOCK_EnableClock(TEST_LED_CLOCK); CLOCK_EnableClock(TEST_LED_CLOCK);
PORT_SetPinMux(TEST_LED_PORT, TEST_LED_PIN, kPORT_MuxAsGpio); PORT_SetPinMux(TEST_LED_PORT, TEST_LED_PIN, kPORT_MuxAsGpio);
GPIO_PinInit(TEST_LED_GPIO, TEST_LED_PIN, &(gpio_pin_config_t){kGPIO_DigitalOutput, 0}); GPIO_PinInit(TEST_LED_GPIO, TEST_LED_PIN, &(gpio_pin_config_t){kGPIO_DigitalOutput, 0});
TEST_LED_ON(); TestLed_On();
} }

View File

@@ -15,10 +15,21 @@
#define TEST_LED_CLOCK kCLOCK_PortB #define TEST_LED_CLOCK kCLOCK_PortB
#define TEST_LED_PIN 13 #define TEST_LED_PIN 13
#define TEST_LED_ON() GPIO_SetPinsOutput(TEST_LED_GPIO, 1U << TEST_LED_PIN) static inline void TestLed_On(void) {
#define TEST_LED_OFF() GPIO_ClearPinsOutput(TEST_LED_GPIO, 1U << TEST_LED_PIN) GPIO_SetPinsOutput(TEST_LED_GPIO, 1U << TEST_LED_PIN);
#define TEST_LED_SET(state) GPIO_WritePinOutput(TEST_LED_GPIO, TEST_LED_PIN, (state)) }
#define TEST_LED_TOGGLE() GPIO_TogglePinsOutput(TEST_LED_GPIO, 1U << TEST_LED_PIN)
static inline void TestLed_Off(void) {
GPIO_ClearPinsOutput(TEST_LED_GPIO, 1U << TEST_LED_PIN);
}
static inline void TestLed_Set(bool state) {
GPIO_WritePinOutput(TEST_LED_GPIO, TEST_LED_PIN, state);
}
static inline void TestLed_Toggle(void) {
GPIO_TogglePinsOutput(TEST_LED_GPIO, 1U << TEST_LED_PIN);
}
// Functions: // Functions:

View File

@@ -7,7 +7,7 @@
void PIT_KEY_DEBOUNCER_HANDLER(void) void PIT_KEY_DEBOUNCER_HANDLER(void)
{ {
TEST_LED_TOGGLE(); TestLed_Toggle();
for (uint8_t slotId=0; slotId<SLOT_COUNT; slotId++) { for (uint8_t slotId=0; slotId<SLOT_COUNT; slotId++) {
for (uint8_t keyId=0; keyId<MAX_KEY_COUNT_PER_MODULE; keyId++) { for (uint8_t keyId=0; keyId<MAX_KEY_COUNT_PER_MODULE; keyId++) {
uint8_t *debounceCounter = &KeyStates[slotId][keyId].debounceCounter; uint8_t *debounceCounter = &KeyStates[slotId][keyId].debounceCounter;

View File

@@ -6,5 +6,5 @@ void TestLed_Init(void)
CLOCK_EnableClock(TEST_LED_CLOCK); CLOCK_EnableClock(TEST_LED_CLOCK);
PORT_SetPinMux(TEST_LED_GPIO_PORT, TEST_LED_GPIO_PIN, kPORT_MuxAsGpio); PORT_SetPinMux(TEST_LED_GPIO_PORT, TEST_LED_GPIO_PIN, kPORT_MuxAsGpio);
GPIO_PinInit(TEST_LED_GPIO, TEST_LED_GPIO_PIN, &(gpio_pin_config_t){kGPIO_DigitalOutput, 1}); GPIO_PinInit(TEST_LED_GPIO, TEST_LED_GPIO_PIN, &(gpio_pin_config_t){kGPIO_DigitalOutput, 1});
TEST_LED_ON(); TestLed_On();
} }

View File

@@ -15,10 +15,25 @@
#define TEST_LED_CLOCK kCLOCK_PortD #define TEST_LED_CLOCK kCLOCK_PortD
#define TEST_LED_GPIO_PIN 7U #define TEST_LED_GPIO_PIN 7U
#define TEST_LED_ON() GPIO_SetPinsOutput(TEST_LED_GPIO, 1U << TEST_LED_GPIO_PIN) static inline void TestLed_On(void)
#define TEST_LED_OFF() GPIO_ClearPinsOutput(TEST_LED_GPIO, 1U << TEST_LED_GPIO_PIN) {
#define TEST_LED_SET(state) GPIO_WritePinOutput(TEST_LED_GPIO, TEST_LED_GPIO_PIN, (state)) GPIO_SetPinsOutput(TEST_LED_GPIO, 1U << TEST_LED_GPIO_PIN);
#define TEST_LED_TOGGLE() GPIO_TogglePinsOutput(TEST_LED_GPIO, 1U << TEST_LED_GPIO_PIN) }
static inline void TestLed_Off(void)
{
GPIO_ClearPinsOutput(TEST_LED_GPIO, 1U << TEST_LED_GPIO_PIN);
}
static inline void TestLed_Set(bool state)
{
GPIO_WritePinOutput(TEST_LED_GPIO, TEST_LED_GPIO_PIN, state);
}
static inline void TestLed_Toggle(void)
{
GPIO_TogglePinsOutput(TEST_LED_GPIO, 1U << TEST_LED_GPIO_PIN);
}
// Functions: // Functions:

View File

@@ -6,6 +6,6 @@
void UsbCommand_SetTestLed(void) void UsbCommand_SetTestLed(void)
{ {
bool isTestLedOn = GetUsbRxBufferUint8(1); bool isTestLedOn = GetUsbRxBufferUint8(1);
TEST_LED_SET(isTestLedOn); TestLed_Set(isTestLedOn);
UhkModuleStates[UhkModuleDriverId_LeftKeyboardHalf].sourceVars.isTestLedOn = isTestLedOn; UhkModuleStates[UhkModuleDriverId_LeftKeyboardHalf].sourceVars.isTestLedOn = isTestLedOn;
} }