PaulStoffregen 9 jaren geleden
bovenliggende
commit
c2f550d378
4 gewijzigde bestanden met toevoegingen van 88 en 0 verwijderingen
  1. +6
    -0
      teensy3/HardwareSerial.h
  2. +30
    -0
      teensy3/serial1.c
  3. +26
    -0
      teensy3/serial2.c
  4. +26
    -0
      teensy3/serial3.c

+ 6
- 0
teensy3/HardwareSerial.h Bestand weergeven

@@ -113,6 +113,8 @@ void serial_begin(uint32_t divisor);
void serial_format(uint32_t format);
void serial_end(void);
void serial_set_transmit_pin(uint8_t pin);
int serial_set_rts(uint8_t pin);
int serial_set_cts(uint8_t pin);
void serial_putchar(uint32_t c);
void serial_write(const void *buf, unsigned int count);
void serial_flush(void);
@@ -130,6 +132,8 @@ void serial2_begin(uint32_t divisor);
void serial2_format(uint32_t format);
void serial2_end(void);
void serial2_set_transmit_pin(uint8_t pin);
int serial2_set_rts(uint8_t pin);
int serial2_set_cts(uint8_t pin);
void serial2_putchar(uint32_t c);
void serial2_write(const void *buf, unsigned int count);
void serial2_flush(void);
@@ -143,6 +147,8 @@ void serial3_begin(uint32_t divisor);
void serial3_format(uint32_t format);
void serial3_end(void);
void serial3_set_transmit_pin(uint8_t pin);
int serial3_set_rts(uint8_t pin);
int serial3_set_cts(uint8_t pin);
void serial3_putchar(uint32_t c);
void serial3_write(const void *buf, unsigned int count);
void serial3_flush(void);

+ 30
- 0
teensy3/serial1.c Bestand weergeven

@@ -172,6 +172,36 @@ void serial_set_transmit_pin(uint8_t pin)
#endif
}

int serial_set_rts(uint8_t pin)
{
if (!(SIM_SCGC4 & SIM_SCGC4_UART0)) return 0;
if (pin == 6) {
CORE_PIN6_CONFIG = PORT_PCR_MUX(3);
} else if (pin == 19) {
CORE_PIN19_CONFIG = PORT_PCR_MUX(3);
} else {
UART0_MODEM &= ~UART_MODEM_RXRTSE;
return 0;
}
UART0_MODEM |= UART_MODEM_RXRTSE;
return 1;
}

int serial_set_cts(uint8_t pin)
{
if (!(SIM_SCGC4 & SIM_SCGC4_UART0)) return 0;
if (pin == 18) {
CORE_PIN18_CONFIG = PORT_PCR_MUX(3); // TODO: weak pullup or pulldown?
} else if (pin == 20) {
CORE_PIN20_CONFIG = PORT_PCR_MUX(3); // TODO: weak pullup or pulldown?
} else {
UART0_MODEM &= ~UART_MODEM_TXCTSE;
return 0;
}
UART0_MODEM |= UART_MODEM_TXCTSE;
return 1;
}

void serial_putchar(uint32_t c)
{
uint32_t head, n;

+ 26
- 0
teensy3/serial2.c Bestand weergeven

@@ -177,6 +177,32 @@ void serial2_set_transmit_pin(uint8_t pin)
#endif
}

int serial2_set_rts(uint8_t pin)
{
if (!(SIM_SCGC4 & SIM_SCGC4_UART1)) return 0;
if (pin == 22) {
CORE_PIN22_CONFIG = PORT_PCR_MUX(3);
} else {
UART1_MODEM &= ~UART_MODEM_RXRTSE;
return 0;
}
UART1_MODEM |= UART_MODEM_RXRTSE;
return 1;
}

int serial2_set_cts(uint8_t pin)
{
if (!(SIM_SCGC4 & SIM_SCGC4_UART1)) return 0;
if (pin == 23) {
CORE_PIN23_CONFIG = PORT_PCR_MUX(3); // TODO: weak pullup or pulldown?
} else {
UART1_MODEM &= ~UART_MODEM_TXCTSE;
return 0;
}
UART1_MODEM |= UART_MODEM_TXCTSE;
return 1;
}

void serial2_putchar(uint32_t c)
{
uint32_t head, n;

+ 26
- 0
teensy3/serial3.c Bestand weergeven

@@ -161,6 +161,32 @@ void serial3_set_transmit_pin(uint8_t pin)
#endif
}

int serial3_set_rts(uint8_t pin)
{
if (!(SIM_SCGC4 & SIM_SCGC4_UART2)) return 0;
if (pin == 2) {
CORE_PIN2_CONFIG = PORT_PCR_MUX(3);
} else {
UART2_MODEM &= ~UART_MODEM_RXRTSE;
return 0;
}
UART2_MODEM |= UART_MODEM_RXRTSE;
return 1;
}

int serial3_set_cts(uint8_t pin)
{
if (!(SIM_SCGC4 & SIM_SCGC4_UART2)) return 0;
if (pin == 14) {
CORE_PIN14_CONFIG = PORT_PCR_MUX(3); // TODO: weak pullup or pulldown?
} else {
UART2_MODEM &= ~UART_MODEM_TXCTSE;
return 0;
}
UART2_MODEM |= UART_MODEM_TXCTSE;
return 1;
}

void serial3_putchar(uint32_t c)
{
uint32_t head, n;

Laden…
Annuleren
Opslaan