Skip to content

Commit e48fad5

Browse files
committed
uart: enable selecting polarity of UART input and output pins.
use flag-set or flag-unset: "uart0-tx-inv" "uart0-rx-inv" "uart1-tx-inv" This comes in handy e.g. for driving led pixels without the need to add a hardware inverter.
1 parent c02bc83 commit e48fad5

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

config.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,15 @@ static const config_flag_name_t config_flag_names[] =
4141
{ flag_bh_high_sens, "bh-high-sens" },
4242
{ flag_cpu_high_speed, "cpu-high-speed" },
4343
{ flag_wlan_power_save, "wlan-power-save" },
44-
{ flag_unused_1, "unused-1", },
45-
{ flag_unused_2, "unused-2", },
44+
{ flag_uart0_tx_inv, "uart0-tx-inv", },
45+
{ flag_uart0_rx_inv, "uart0-rx-inv", },
4646
{ flag_log_to_buffer, "log-to-buffer" },
4747
{ flag_auto_sequencer, "auto-sequencer" },
4848
{ flag_pwm1_extend, "pwm1-extend" },
4949
{ flag_tmd_high_sens, "tmd-high-sens" },
5050
{ flag_apds3_high_sens, "apds3-high-sens" },
5151
{ flag_apds6_high_sens, "apds6-high-sens" },
52+
{ flag_uart1_tx_inv, "uart1-tx-inv", },
5253
{ flag_none, "" },
5354
};
5455

config.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@ enum
2121
flag_bh_high_sens = 1 << 3,
2222
flag_cpu_high_speed = 1 << 4,
2323
flag_wlan_power_save = 1 << 5,
24-
flag_unused_1 = 1 << 6,
25-
flag_unused_2 = 1 << 7,
24+
flag_uart0_tx_inv = 1 << 6,
25+
flag_uart0_rx_inv = 1 << 7,
2626
flag_log_to_buffer = 1 << 8,
2727
flag_auto_sequencer = 1 << 9,
2828
flag_pwm1_extend = 1 << 10,
2929
flag_tmd_high_sens = 1 << 11,
3030
flag_apds3_high_sens = 1 << 12,
3131
flag_apds6_high_sens = 1 << 13,
32+
flag_uart1_tx_inv = 1 << 14,
3233
};
3334

3435
void config_flags_to_string(_Bool nl, const char *, string_t *);

uart.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,15 @@ irom void uart_init(void)
307307
// If the fifo contains less than this numbers of bytes, raise an
308308
// interrupt.
309309

310+
clear_set_peri_reg_mask(UART_CONF0(0),
311+
(UART_RXD_INV | UART_TXD_INV),
312+
((config_flags_match(flag_uart0_tx_inv)) ? UART_TXD_INV : 0) |
313+
((config_flags_match(flag_uart0_rx_inv)) ? UART_RXD_INV : 0));
314+
315+
clear_set_peri_reg_mask(UART_CONF0(1),
316+
(UART_RXD_INV | UART_TXD_INV),
317+
((config_flags_match(flag_uart1_tx_inv)) ? UART_TXD_INV : 0));
318+
310319
write_peri_reg(UART_CONF1(0),
311320
((2 & UART_RX_TOUT_THRHD) << UART_RX_TOUT_THRHD_S) |
312321
UART_RX_TOUT_EN |

0 commit comments

Comments
 (0)