Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update GPIO macro usages in core #23093

Merged
merged 3 commits into from
Feb 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions drivers/bluetooth/bluefruit_le.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ static bool sdep_recv_pkt(struct sdep_msg *msg, uint16_t timeout) {
bool ready = false;

do {
ready = readPin(BLUEFRUIT_LE_IRQ_PIN);
ready = gpio_read_pin(BLUEFRUIT_LE_IRQ_PIN);
if (ready) {
break;
}
Expand Down Expand Up @@ -231,7 +231,7 @@ static void resp_buf_read_one(bool greedy) {
return;
}

if (readPin(BLUEFRUIT_LE_IRQ_PIN)) {
if (gpio_read_pin(BLUEFRUIT_LE_IRQ_PIN)) {
struct sdep_msg msg;

again:
Expand All @@ -242,7 +242,7 @@ static void resp_buf_read_one(bool greedy) {
dprintf("recv latency %dms\n", TIMER_DIFF_16(timer_read(), last_send));
}

if (greedy && resp_buf.peek(last_send) && readPin(BLUEFRUIT_LE_IRQ_PIN)) {
if (greedy && resp_buf.peek(last_send) && gpio_read_pin(BLUEFRUIT_LE_IRQ_PIN)) {
goto again;
}
}
Expand Down Expand Up @@ -293,16 +293,16 @@ void bluefruit_le_init(void) {
state.configured = false;
state.is_connected = false;

setPinInput(BLUEFRUIT_LE_IRQ_PIN);
gpio_set_pin_input(BLUEFRUIT_LE_IRQ_PIN);

spi_init();

// Perform a hardware reset
setPinOutput(BLUEFRUIT_LE_RST_PIN);
writePinHigh(BLUEFRUIT_LE_RST_PIN);
writePinLow(BLUEFRUIT_LE_RST_PIN);
gpio_set_pin_output(BLUEFRUIT_LE_RST_PIN);
gpio_write_pin_high(BLUEFRUIT_LE_RST_PIN);
gpio_write_pin_low(BLUEFRUIT_LE_RST_PIN);
wait_ms(10);
writePinHigh(BLUEFRUIT_LE_RST_PIN);
gpio_write_pin_high(BLUEFRUIT_LE_RST_PIN);

wait_ms(1000); // Give it a second to initialize

Expand Down Expand Up @@ -508,7 +508,7 @@ void bluefruit_le_task(void) {
resp_buf_read_one(true);
send_buf_send_one(SdepShortTimeout);

if (resp_buf.empty() && (state.event_flags & UsingEvents) && readPin(BLUEFRUIT_LE_IRQ_PIN)) {
if (resp_buf.empty() && (state.event_flags & UsingEvents) && gpio_read_pin(BLUEFRUIT_LE_IRQ_PIN)) {
// Must be an event update
if (at_command_P(PSTR("AT+EVENTSTATUS"), resbuf, sizeof(resbuf))) {
uint32_t mask = strtoul(resbuf, NULL, 16);
Expand Down
12 changes: 6 additions & 6 deletions drivers/eeprom/eeprom_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ void eeprom_driver_init(void) {
i2c_init();
#if defined(EXTERNAL_EEPROM_WP_PIN)
/* We are setting the WP pin to high in a way that requires at least two bit-flips to change back to 0 */
writePin(EXTERNAL_EEPROM_WP_PIN, 1);
setPinInputHigh(EXTERNAL_EEPROM_WP_PIN);
gpio_write_pin(EXTERNAL_EEPROM_WP_PIN, 1);
gpio_set_pin_input_high(EXTERNAL_EEPROM_WP_PIN);
#endif
}

Expand Down Expand Up @@ -100,8 +100,8 @@ void eeprom_write_block(const void *buf, void *addr, size_t len) {
uintptr_t target_addr = (uintptr_t)addr;

#if defined(EXTERNAL_EEPROM_WP_PIN)
setPinOutput(EXTERNAL_EEPROM_WP_PIN);
writePin(EXTERNAL_EEPROM_WP_PIN, 0);
gpio_set_pin_output(EXTERNAL_EEPROM_WP_PIN);
gpio_write_pin(EXTERNAL_EEPROM_WP_PIN, 0);
#endif

while (len > 0) {
Expand Down Expand Up @@ -134,7 +134,7 @@ void eeprom_write_block(const void *buf, void *addr, size_t len) {

#if defined(EXTERNAL_EEPROM_WP_PIN)
/* We are setting the WP pin to high in a way that requires at least two bit-flips to change back to 0 */
writePin(EXTERNAL_EEPROM_WP_PIN, 1);
setPinInputHigh(EXTERNAL_EEPROM_WP_PIN);
gpio_write_pin(EXTERNAL_EEPROM_WP_PIN, 1);
gpio_set_pin_input_high(EXTERNAL_EEPROM_WP_PIN);
#endif
}
24 changes: 12 additions & 12 deletions drivers/gpio/sn74x138.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,39 +27,39 @@ static const pin_t address_pins[ADDRESS_PIN_COUNT] = SN74X138_ADDRESS_PINS;

void sn74x138_init(void) {
for (int i = 0; i < ADDRESS_PIN_COUNT; i++) {
setPinOutput(address_pins[i]);
writePinLow(address_pins[i]);
gpio_set_pin_output(address_pins[i]);
gpio_write_pin_low(address_pins[i]);
}

#if defined(SN74X138_E1_PIN)
setPinOutput(SN74X138_E1_PIN);
writePinHigh(SN74X138_E1_PIN);
gpio_set_pin_output(SN74X138_E1_PIN);
gpio_write_pin_high(SN74X138_E1_PIN);
#endif

#if defined(SN74X138_E2_PIN)
setPinOutput(SN74X138_E2_PIN);
writePinHigh(SN74X138_E2_PIN);
gpio_set_pin_output(SN74X138_E2_PIN);
gpio_write_pin_high(SN74X138_E2_PIN);
#endif
#if defined(SN74X138_E3_PIN)
setPinOutput(SN74X138_E3_PIN);
writePinLow(SN74X138_E3_PIN);
gpio_set_pin_output(SN74X138_E3_PIN);
gpio_write_pin_low(SN74X138_E3_PIN);
#endif
}

void sn74x138_set_enabled(bool enabled) {
#if defined(SN74X138_E1_PIN)
writePin(SN74X138_E1_PIN, !enabled);
gpio_write_pin(SN74X138_E1_PIN, !enabled);
#endif
#if defined(SN74X138_E2_PIN)
writePin(SN74X138_E2_PIN, !enabled);
gpio_write_pin(SN74X138_E2_PIN, !enabled);
#endif
#if defined(SN74X138_E3_PIN)
writePin(SN74X138_E3_PIN, enabled);
gpio_write_pin(SN74X138_E3_PIN, enabled);
#endif
}

void sn74x138_set_addr(uint8_t address) {
for (int i = 0; i < ADDRESS_PIN_COUNT; i++) {
writePin(address_pins[i], address & (1 << i));
gpio_write_pin(address_pins[i], address & (1 << i));
}
}
18 changes: 9 additions & 9 deletions drivers/gpio/sn74x154.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,32 @@ static const pin_t address_pins[ADDRESS_PIN_COUNT] = SN74X154_ADDRESS_PINS;

void sn74x154_init(void) {
for (int i = 0; i < ADDRESS_PIN_COUNT; i++) {
setPinOutput(address_pins[i]);
writePinLow(address_pins[i]);
gpio_set_pin_output(address_pins[i]);
gpio_write_pin_low(address_pins[i]);
}

#if defined(SN74X154_E0_PIN)
setPinOutput(SN74X154_E0_PIN);
writePinHigh(SN74X154_E0_PIN);
gpio_set_pin_output(SN74X154_E0_PIN);
gpio_write_pin_high(SN74X154_E0_PIN);
#endif

#if defined(SN74X154_E1_PIN)
setPinOutput(SN74X154_E1_PIN);
writePinHigh(SN74X154_E1_PIN);
gpio_set_pin_output(SN74X154_E1_PIN);
gpio_write_pin_high(SN74X154_E1_PIN);
#endif
}

void sn74x154_set_enabled(bool enabled) {
#if defined(SN74X154_E0_PIN)
writePin(SN74X154_E0_PIN, !enabled);
gpio_write_pin(SN74X154_E0_PIN, !enabled);
#endif
#if defined(SN74X154_E1_PIN)
writePin(SN74X154_E1_PIN, !enabled);
gpio_write_pin(SN74X154_E1_PIN, !enabled);
#endif
}

void sn74x154_set_addr(uint8_t address) {
for (int i = 0; i < ADDRESS_PIN_COUNT; i++) {
writePin(address_pins[i], address & (1 << i));
gpio_write_pin(address_pins[i], address & (1 << i));
}
}
14 changes: 7 additions & 7 deletions drivers/haptic/solenoid.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void solenoid_set_dwell(uint8_t dwell) {
* @param index select which solenoid to check/stop
*/
void solenoid_stop(uint8_t index) {
writePin(solenoid_pads[index], !solenoid_active_state[index]);
gpio_write_pin(solenoid_pads[index], !solenoid_active_state[index]);
solenoid_on[index] = false;
solenoid_buzzing[index] = false;
}
Expand All @@ -78,7 +78,7 @@ void solenoid_fire(uint8_t index) {
solenoid_on[index] = true;
solenoid_buzzing[index] = true;
solenoid_start[index] = timer_read();
writePin(solenoid_pads[index], solenoid_active_state[index]);
gpio_write_pin(solenoid_pads[index], solenoid_active_state[index]);
}

/**
Expand Down Expand Up @@ -128,12 +128,12 @@ void solenoid_check(void) {
if ((elapsed[i] % (SOLENOID_BUZZ_ACTUATED + SOLENOID_BUZZ_NONACTUATED)) < SOLENOID_BUZZ_ACTUATED) {
if (!solenoid_buzzing[i]) {
solenoid_buzzing[i] = true;
writePin(solenoid_pads[i], solenoid_active_state[i]);
gpio_write_pin(solenoid_pads[i], solenoid_active_state[i]);
}
} else {
if (solenoid_buzzing[i]) {
solenoid_buzzing[i] = false;
writePin(solenoid_pads[i], !solenoid_active_state[i]);
gpio_write_pin(solenoid_pads[i], !solenoid_active_state[i]);
}
}
}
Expand All @@ -156,8 +156,8 @@ void solenoid_setup(void) {
#else
solenoid_active_state[i] = high;
#endif
writePin(solenoid_pads[i], !solenoid_active_state[i]);
setPinOutput(solenoid_pads[i]);
gpio_write_pin(solenoid_pads[i], !solenoid_active_state[i]);
gpio_set_pin_output(solenoid_pads[i]);
if ((!HAPTIC_OFF_IN_LOW_POWER) || (usb_device_state == USB_DEVICE_STATE_CONFIGURED)) {
solenoid_fire(i);
}
Expand All @@ -170,6 +170,6 @@ void solenoid_setup(void) {
*/
void solenoid_shutdown(void) {
for (uint8_t i = 0; i < NUMBER_OF_SOLENOIDS; i++) {
writePin(solenoid_pads[i], !solenoid_active_state[i]);
gpio_write_pin(solenoid_pads[i], !solenoid_active_state[i]);
}
}
48 changes: 24 additions & 24 deletions drivers/lcd/hd44780.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,67 +57,67 @@ static const pin_t data_pins[4] = HD44780_DATA_PINS;
#define HD44780_ENABLE_DELAY_US 1

static void hd44780_latch(void) {
writePinHigh(HD44780_E_PIN);
gpio_write_pin_high(HD44780_E_PIN);
wait_us(HD44780_ENABLE_DELAY_US);
writePinLow(HD44780_E_PIN);
gpio_write_pin_low(HD44780_E_PIN);
}

void hd44780_write(uint8_t data, bool isData) {
writePin(HD44780_RS_PIN, isData);
writePinLow(HD44780_RW_PIN);
gpio_write_pin(HD44780_RS_PIN, isData);
gpio_write_pin_low(HD44780_RW_PIN);

for (int i = 0; i < 4; i++) {
setPinOutput(data_pins[i]);
gpio_set_pin_output(data_pins[i]);
}

// Write high nibble
for (int i = 0; i < 4; i++) {
writePin(data_pins[i], (data >> 4) & (1 << i));
gpio_write_pin(data_pins[i], (data >> 4) & (1 << i));
}
hd44780_latch();

// Write low nibble
for (int i = 0; i < 4; i++) {
writePin(data_pins[i], data & (1 << i));
gpio_write_pin(data_pins[i], data & (1 << i));
}
hd44780_latch();

for (int i = 0; i < 4; i++) {
writePinHigh(data_pins[i]);
gpio_write_pin_high(data_pins[i]);
}
}

uint8_t hd44780_read(bool isData) {
uint8_t data = 0;

writePin(HD44780_RS_PIN, isData);
writePinHigh(HD44780_RW_PIN);
gpio_write_pin(HD44780_RS_PIN, isData);
gpio_write_pin_high(HD44780_RW_PIN);

for (int i = 0; i < 4; i++) {
setPinInput(data_pins[i]);
gpio_set_pin_input(data_pins[i]);
}

writePinHigh(HD44780_E_PIN);
gpio_write_pin_high(HD44780_E_PIN);
wait_us(HD44780_ENABLE_DELAY_US);

// Read high nibble
for (int i = 0; i < 4; i++) {
data |= (readPin(data_pins[i]) << i);
data |= (gpio_read_pin(data_pins[i]) << i);
}

data <<= 4;

writePinLow(HD44780_E_PIN);
gpio_write_pin_low(HD44780_E_PIN);
wait_us(HD44780_ENABLE_DELAY_US);
writePinHigh(HD44780_E_PIN);
gpio_write_pin_high(HD44780_E_PIN);
wait_us(HD44780_ENABLE_DELAY_US);

// Read low nibble
for (int i = 0; i < 4; i++) {
data |= (readPin(data_pins[i]) << i);
data |= (gpio_read_pin(data_pins[i]) << i);
}

writePinLow(HD44780_E_PIN);
gpio_write_pin_low(HD44780_E_PIN);

return data;
}
Expand Down Expand Up @@ -171,20 +171,20 @@ void hd44780_set_ddram_address(uint8_t address) {
}

void hd44780_init(bool cursor, bool blink) {
setPinOutput(HD44780_RS_PIN);
setPinOutput(HD44780_RW_PIN);
setPinOutput(HD44780_E_PIN);
gpio_set_pin_output(HD44780_RS_PIN);
gpio_set_pin_output(HD44780_RW_PIN);
gpio_set_pin_output(HD44780_E_PIN);

for (int i = 0; i < 4; i++) {
setPinOutput(data_pins[i]);
gpio_set_pin_output(data_pins[i]);
}

wait_ms(HD44780_INIT_DELAY_MS);

// Manually configure for 4-bit mode - can't use hd44780_command() yet
// HD44780U datasheet, Fig. 24 (p46)
writePinHigh(data_pins[0]); // Function set
writePinHigh(data_pins[1]); // DL = 1
gpio_write_pin_high(data_pins[0]); // Function set
gpio_write_pin_high(data_pins[1]); // DL = 1
hd44780_latch();
wait_ms(5);
// Send again
Expand All @@ -194,7 +194,7 @@ void hd44780_init(bool cursor, bool blink) {
hd44780_latch();
wait_us(64);

writePinLow(data_pins[0]); // DL = 0
gpio_write_pin_low(data_pins[0]); // DL = 0
hd44780_latch();
wait_us(64);

Expand Down
16 changes: 8 additions & 8 deletions drivers/lcd/st7565.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ static void InvertCharacter(uint8_t *cursor) {
}

bool st7565_init(display_rotation_t rotation) {
setPinOutput(ST7565_A0_PIN);
writePinHigh(ST7565_A0_PIN);
setPinOutput(ST7565_RST_PIN);
writePinHigh(ST7565_RST_PIN);
gpio_set_pin_output(ST7565_A0_PIN);
gpio_write_pin_high(ST7565_A0_PIN);
gpio_set_pin_output(ST7565_RST_PIN);
gpio_write_pin_high(ST7565_RST_PIN);

st7565_rotation = st7565_init_user(rotation);

Expand Down Expand Up @@ -488,18 +488,18 @@ void st7565_task(void) {
__attribute__((weak)) void st7565_task_user(void) {}

void st7565_reset(void) {
writePinLow(ST7565_RST_PIN);
gpio_write_pin_low(ST7565_RST_PIN);
wait_ms(20);
writePinHigh(ST7565_RST_PIN);
gpio_write_pin_high(ST7565_RST_PIN);
wait_ms(20);
}

spi_status_t st7565_send_cmd(uint8_t cmd) {
writePinLow(ST7565_A0_PIN);
gpio_write_pin_low(ST7565_A0_PIN);
return spi_write(cmd);
}

spi_status_t st7565_send_data(uint8_t *data, uint16_t length) {
writePinHigh(ST7565_A0_PIN);
gpio_write_pin_high(ST7565_A0_PIN);
return spi_transmit(data, length);
}
Loading
Loading