Skip to content

Commit 86276ec

Browse files
committed
Use constants instead of Bools for deckctrl GPIO API
1 parent 4cf733e commit 86276ec

3 files changed

Lines changed: 16 additions & 16 deletions

File tree

src/deck/api/deckctrl_gpio.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static bool get_i2c_address(DeckInfo* info, uint8_t* address) {
2929
return true;
3030
}
3131

32-
bool deckctrl_gpio_set_direction(DeckInfo* info, DeckCtrlGPIOPin pin, bool output) {
32+
bool deckctrl_gpio_set_direction(DeckInfo* info, DeckCtrlGPIOPin pin, uint32_t direction) {
3333
if (pin >= DECKCTRL_GPIO_PIN_MAX) {
3434
return false;
3535
}
@@ -49,13 +49,13 @@ bool deckctrl_gpio_set_direction(DeckInfo* info, DeckCtrlGPIOPin pin, bool outpu
4949
uint16_t direction_reg = buffer[0] | (buffer[1] << 8);
5050

5151
// Set or clear the bit for this pin
52-
if (output) {
52+
if (direction != INPUT) {
5353
direction_reg |= (1 << pin);
5454
} else {
5555
direction_reg &= ~(1 << pin);
5656
}
5757

58-
DEBUG_PRINT("Setting GPIO pin %d direction to %s (reg=0x%04x)\n", pin, output ? "output" : "input", direction_reg);
58+
DEBUG_PRINT("Setting GPIO pin %d direction to %s (reg=0x%04x)\n", pin, (direction!=INPUT) ? "output" : "input", direction_reg);
5959

6060
// Convert back to bytes and write
6161
buffer[0] = direction_reg & 0xFF;
@@ -66,7 +66,7 @@ bool deckctrl_gpio_set_direction(DeckInfo* info, DeckCtrlGPIOPin pin, bool outpu
6666
return result;
6767
}
6868

69-
bool deckctrl_gpio_write(DeckInfo* info, DeckCtrlGPIOPin pin, bool value) {
69+
bool deckctrl_gpio_write(DeckInfo* info, DeckCtrlGPIOPin pin, uint32_t value) {
7070
if (pin >= DECKCTRL_GPIO_PIN_MAX) {
7171
return false;
7272
}
@@ -86,7 +86,7 @@ bool deckctrl_gpio_write(DeckInfo* info, DeckCtrlGPIOPin pin, bool value) {
8686
uint16_t value_reg = buffer[0] | (buffer[1] << 8);
8787

8888
// Set or clear the bit for this pin
89-
if (value) {
89+
if (value != LOW) {
9090
value_reg |= (1 << pin);
9191
} else {
9292
value_reg &= ~(1 << pin);
@@ -99,7 +99,7 @@ bool deckctrl_gpio_write(DeckInfo* info, DeckCtrlGPIOPin pin, bool value) {
9999
return i2cdevWriteReg16(I2C1_DEV, i2c_address, DECKCTRL_GPIO_VALUE_REG, 2, buffer);
100100
}
101101

102-
bool deckctrl_gpio_read(DeckInfo* info, DeckCtrlGPIOPin pin, bool* value) {
102+
bool deckctrl_gpio_read(DeckInfo* info, DeckCtrlGPIOPin pin, uint32_t * value) {
103103
if (pin >= DECKCTRL_GPIO_PIN_MAX || value == NULL) {
104104
return false;
105105
}
@@ -119,7 +119,7 @@ bool deckctrl_gpio_read(DeckInfo* info, DeckCtrlGPIOPin pin, bool* value) {
119119
uint16_t value_reg = buffer[0] | (buffer[1] << 8);
120120

121121
// Extract the bit for this pin
122-
*value = (value_reg & (1 << pin)) != 0;
122+
*value = ((value_reg & (1 << pin)) != 0)?HIGH:LOW;
123123

124124
return true;
125125
}

src/deck/backends/Kconfig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ config DECK_BACKEND_ONEWIRE
1010
help
1111
Enable the OneWire deck discovery backend that scans for decks with
1212
OneWire memory chips. Disable this if you want to ignore all
13-
OneWire-based deck discovery, which might be useful for debugging.
13+
OneWire-based deck discovery.
1414

1515
config DECK_BACKEND_DECKCTRL
1616
bool "Enable DeckCtrl deck discovery backend"
1717
default y
1818
help
1919
Enable the DeckCtrl deck discovery backend that scans for decks
2020
with DeckCtrl chip. Disable this if you want to ignore all
21-
DeckCtrl-based deck discovery, which might be useful for debugging.
21+
DeckCtrl-based deck discovery.
2222

2323
config DECK_BACKEND_DECKCTRL_DEBUG
2424
depends on DECK_BACKEND_DECKCTRL

src/deck/drivers/src/deckctrl_devboard.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Deck control dev board driver
33
*
4-
* This deck driver exercise the deck control dev board
4+
* This deck driver exercises the deck control dev board
55
* It is used to test the deck control dev board
66
* and can be used as a reference for other deck drivers.
77
*
@@ -23,26 +23,26 @@ static void task(void* param) {
2323

2424
// Put all GPIO pins as output and set them low
2525
for (int i = 0; i < N_LEDS; i++) {
26-
deckctrl_gpio_set_direction(info, (DeckCtrlGPIOPin)i, true);
27-
deckctrl_gpio_write(info, (DeckCtrlGPIOPin)i, false);
26+
deckctrl_gpio_set_direction(info, (DeckCtrlGPIOPin)i, OUTPUT);
27+
deckctrl_gpio_write(info, (DeckCtrlGPIOPin)i, LOW);
2828
}
2929

3030
while (1) {
3131
// Blink all pins in sequence
3232
for (int i = 0; i < N_LEDS; i++) {
33-
deckctrl_gpio_write(info, (DeckCtrlGPIOPin)i, true);
33+
deckctrl_gpio_write(info, (DeckCtrlGPIOPin)i, HIGH);
3434
vTaskDelay(100 / portTICK_PERIOD_MS);
35-
deckctrl_gpio_write(info, (DeckCtrlGPIOPin)i, false);
35+
deckctrl_gpio_write(info, (DeckCtrlGPIOPin)i, LOW);
3636
}
3737

3838
// All ON then all OFF
3939
for (int i = 0; i < N_LEDS; i++) {
40-
deckctrl_gpio_write(info, (DeckCtrlGPIOPin)i, true);
40+
deckctrl_gpio_write(info, (DeckCtrlGPIOPin)i, HIGH);
4141
vTaskDelay(100 / portTICK_PERIOD_MS);
4242
}
4343

4444
for (int i = 0; i < N_LEDS; i++) {
45-
deckctrl_gpio_write(info, (DeckCtrlGPIOPin)i, false);
45+
deckctrl_gpio_write(info, (DeckCtrlGPIOPin)i, LOW);
4646
vTaskDelay(100 / portTICK_PERIOD_MS);
4747
}
4848
}

0 commit comments

Comments
 (0)