Bringing Massdrop keyboard hardware configuration to keyboard level (#4593)

MCU Pins for debugging, LED, boot tracing, and shift registers are now configurable at keyboard level.
Macros led_* replaced by DBG_LED_*
Macros m15_* replaced by DBG_1_*
Macros m27_* replaced by DBG_2_*
Macros m28_* replaced by DBG_3_*
For CTRL and ALT keyboards, debug boot tracing pin default now set to pad M27 instead of M28 since although M28 is not being used, it is technically a signal for USB port detection.
m15_print(...) renamed to dbg_print(...) to get away from hard coded port names.
dbg_print function now follows similar pattern to debug led output.
This commit is contained in:
patrickmt
2018-12-10 14:28:06 -05:00
committed by Drashna Jaelre
parent e99615b2ac
commit 4a5e68f4f2
12 changed files with 374 additions and 185 deletions

View File

@ -77,7 +77,6 @@ void USB2422_init(void)
Port *pport = PORT;
Oscctrl *posc = OSCCTRL;
Usb *pusb = USB;
Srdata_t *pspi = &srdata;
DBGC(DC_USB2422_INIT_BEGIN);
@ -132,9 +131,9 @@ void USB2422_init(void)
i2c0_init(); //IC2 clk must be high at USB2422 reset release time to signal SMB configuration
pspi->bit.HUB_CONNECT = 1; //connect signal
pspi->bit.HUB_RESET_N = 1; //reset high
SPI_WriteSRData();
sr_exp_data.bit.HUB_CONNECT = 1; //connect signal
sr_exp_data.bit.HUB_RESET_N = 1; //reset high
SR_EXP_WriteData();
CLK_delay_us(100);
@ -150,16 +149,14 @@ void USB2422_init(void)
void USB_reset(void)
{
Srdata_t *pspi = &srdata;
DBGC(DC_USB_RESET_BEGIN);
//pulse reset for at least 1 usec
pspi->bit.HUB_RESET_N = 0; //reset low
SPI_WriteSRData();
sr_exp_data.bit.HUB_RESET_N = 0; //reset low
SR_EXP_WriteData();
CLK_delay_us(1);
pspi->bit.HUB_RESET_N = 1; //reset high to run
SPI_WriteSRData();
sr_exp_data.bit.HUB_RESET_N = 1; //reset high to run
SR_EXP_WriteData();
CLK_delay_us(1);
DBGC(DC_USB_RESET_COMPLETE);
@ -241,14 +238,14 @@ void USB_set_host_by_voltage(void)
#ifndef MD_BOOTLOADER
usb_extra_state = USB_EXTRA_STATE_UNKNOWN;
#endif //MD_BOOTLOADER
srdata.bit.SRC_1 = 1; //USBC-1 available for test
srdata.bit.SRC_2 = 1; //USBC-2 available for test
srdata.bit.E_UP_N = 1; //HOST disable
srdata.bit.E_DN1_N = 1; //EXTRA disable
srdata.bit.E_VBUS_1 = 0; //USBC-1 disable full power I/O
srdata.bit.E_VBUS_2 = 0; //USBC-2 disable full power I/O
sr_exp_data.bit.SRC_1 = 1; //USBC-1 available for test
sr_exp_data.bit.SRC_2 = 1; //USBC-2 available for test
sr_exp_data.bit.E_UP_N = 1; //HOST disable
sr_exp_data.bit.E_DN1_N = 1; //EXTRA disable
sr_exp_data.bit.E_VBUS_1 = 0; //USBC-1 disable full power I/O
sr_exp_data.bit.E_VBUS_2 = 0; //USBC-2 disable full power I/O
SPI_WriteSRData();
SR_EXP_WriteData();
CLK_delay_ms(250);
@ -262,37 +259,37 @@ void USB_set_host_by_voltage(void)
if (v_con_1 > v_con_2)
{
srdata.bit.S_UP = 0; //HOST to USBC-1
srdata.bit.S_DN1 = 1; //EXTRA to USBC-2
srdata.bit.SRC_1 = 1; //HOST on USBC-1
srdata.bit.SRC_2 = 0; //EXTRA available on USBC-2
sr_exp_data.bit.S_UP = 0; //HOST to USBC-1
sr_exp_data.bit.S_DN1 = 1; //EXTRA to USBC-2
sr_exp_data.bit.SRC_1 = 1; //HOST on USBC-1
sr_exp_data.bit.SRC_2 = 0; //EXTRA available on USBC-2
srdata.bit.E_VBUS_1 = 1; //USBC-1 enable full power I/O
srdata.bit.E_VBUS_2 = 0; //USBC-2 disable full power I/O
sr_exp_data.bit.E_VBUS_1 = 1; //USBC-1 enable full power I/O
sr_exp_data.bit.E_VBUS_2 = 0; //USBC-2 disable full power I/O
SPI_WriteSRData();
SR_EXP_WriteData();
srdata.bit.E_UP_N = 0; //HOST enable
sr_exp_data.bit.E_UP_N = 0; //HOST enable
SPI_WriteSRData();
SR_EXP_WriteData();
usb_host_port = USB_HOST_PORT_1;
}
else
{
srdata.bit.S_UP = 1; //EXTRA to USBC-1
srdata.bit.S_DN1 = 0; //HOST to USBC-2
srdata.bit.SRC_1 = 0; //EXTRA available on USBC-1
srdata.bit.SRC_2 = 1; //HOST on USBC-2
sr_exp_data.bit.S_UP = 1; //EXTRA to USBC-1
sr_exp_data.bit.S_DN1 = 0; //HOST to USBC-2
sr_exp_data.bit.SRC_1 = 0; //EXTRA available on USBC-1
sr_exp_data.bit.SRC_2 = 1; //HOST on USBC-2
srdata.bit.E_VBUS_1 = 0; //USBC-1 disable full power I/O
srdata.bit.E_VBUS_2 = 1; //USBC-2 enable full power I/O
sr_exp_data.bit.E_VBUS_1 = 0; //USBC-1 disable full power I/O
sr_exp_data.bit.E_VBUS_2 = 1; //USBC-2 enable full power I/O
SPI_WriteSRData();
SR_EXP_WriteData();
srdata.bit.E_UP_N = 0; //HOST enable
sr_exp_data.bit.E_UP_N = 0; //HOST enable
SPI_WriteSRData();
SR_EXP_WriteData();
usb_host_port = USB_HOST_PORT_2;
}
@ -325,15 +322,15 @@ uint8_t USB2422_Port_Detect_Init(void)
if (v_con_1 > v_con_2) //Values updated from USB_set_host_by_voltage();
{
//1 flash for port 1 detected
if (tmod > 500 && tmod < 600) { led_on; }
else { led_off; }
if (tmod > 500 && tmod < 600) { DBG_LED_ON; }
else { DBG_LED_OFF; }
}
else if (v_con_2 > v_con_1) //Values updated from USB_set_host_by_voltage();
{
//2 flash for port 2 detected
if (tmod > 500 && tmod < 600) { led_on; }
else if (tmod > 700 && tmod < 800) { led_on; }
else { led_off; }
if (tmod > 500 && tmod < 600) { DBG_LED_ON; }
else if (tmod > 700 && tmod < 800) { DBG_LED_ON; }
else { DBG_LED_OFF; }
}
if (CLK_get_ms() > port_detect_retry_ms)
@ -357,12 +354,12 @@ void USB_ExtraSetState(uint8_t state)
if (state == USB_EXTRA_STATE_DISABLED_UNTIL_REPLUG)
state = USB_EXTRA_STATE_DISABLED;
if (usb_host_port == USB_HOST_PORT_1) srdata.bit.E_VBUS_2 = state;
else if (usb_host_port == USB_HOST_PORT_2) srdata.bit.E_VBUS_1 = state;
if (usb_host_port == USB_HOST_PORT_1) sr_exp_data.bit.E_VBUS_2 = state;
else if (usb_host_port == USB_HOST_PORT_2) sr_exp_data.bit.E_VBUS_1 = state;
else return;
srdata.bit.E_DN1_N = !state;
SPI_WriteSRData();
sr_exp_data.bit.E_DN1_N = !state;
SR_EXP_WriteData();
usb_extra_state = state_save;