diff --git a/stm32/COLDCARD_Q1/modckcc.c b/stm32/COLDCARD_Q1/modckcc.c index 408ad196..c7eb8ff9 100644 --- a/stm32/COLDCARD_Q1/modckcc.c +++ b/stm32/COLDCARD_Q1/modckcc.c @@ -250,7 +250,7 @@ STATIC mp_obj_t watchpoint(volatile mp_obj_t arg1) MP_DEFINE_CONST_FUN_OBJ_1(watchpoint_obj, watchpoint); #define SWAB16(n) (( ((n)>>8) | ((n) << 8) )&0xffff) -#define GREY(n) SWAB16( (n<<11) | (n<<6) | n) +#define GREY(n) SWAB16( (n<<11) | (n<<5) | n) // BGR565 values, but wrong endian, so green split weird static uint16_t palette[16] = { @@ -259,7 +259,7 @@ static uint16_t palette[16] = { SWAB16(0xf800), // 2 => red SWAB16(0x07e0), // 3 => green - SWAB16(0x00f8), // 4 => blue + SWAB16(0x001f), // 4 => blue // some greys: 5 .. 12 GREY(5), GREY(9), GREY(13), GREY(17), GREY(21), GREY(25), GREY(29), diff --git a/stm32/COLDCARD_Q1/pins.csv b/stm32/COLDCARD_Q1/pins.csv index e840247b..5fc561b3 100644 --- a/stm32/COLDCARD_Q1/pins.csv +++ b/stm32/COLDCARD_Q1/pins.csv @@ -69,23 +69,49 @@ SD_D2,PC10 SD_D3,PC11 SD_CMD,PD2 SD_CK,PC12 -SD_SW,PC13 -SD,PA9 -M2_COL0,PB0 -M2_COL1,PB1 -M2_COL2,PB2 -M2_ROW0,PD8 -M2_ROW1,PD9 -M2_ROW2,PD10 -M2_ROW3,PD11 +SD_DETECT,PD3 +SD_DETECT2,PD4 +SD_MUX,PC13 +Q1_COL0,PB0 +Q1_COL1,PB1 +Q1_COL2,PB2 +Q1_COL3,PB5 +Q1_COL4,PB8 +Q1_COL5,PB9 +Q1_COL6,PB10 +Q1_COL7,PD13 +Q1_COL8,PD14 +Q1_COL9,PD15 +Q1_ROW0,PD8 +Q1_ROW1,PD9 +Q1_ROW2,PD10 +Q1_ROW3,PD11 +Q1_ROW4,PD12 +Q1_ROW5,PD7 F_CS,PB9 -SF_SCLK,PB10 -SF_MISO,PC2 -SF_MOSI,PC3 +TURN_OFF,PC0 +NOT_BATTERY,PC1 +NFC_ED,PD6 SD_ACTIVE,PC7 USB_ACTIVE,PC6 SE2_SCL,PB13 SE2_SDA,PB14 NFC_SCL,PB6 NFC_SDA,PB7 -NFC_ED,PC4 +NFC_ACTIVE,PE4 +QR_TX,PA2 +QR_RX,PA3 +QR_RESET,PE0 +QR_TRIG,PE1 +LCD_TEAR,PB11 +PWR_BTN,PB12 +BL_ENABLE,PE3 +LCD_CS,PA4 +LCD_SCLK,PA5 +LCD_RESET,PA6 +LCD_MOSI,PA7 +LCD_DATA_CMD,PA8 +VIN_SENSE,PA1 +G_SWCLK_B0,PE2 +G_CTRL,PE5 +G_RESET,PE6 diff --git a/stm32/mk4-bootloader/sdcard.c b/stm32/mk4-bootloader/sdcard.c index 09c41ad8..626fe295 100644 --- a/stm32/mk4-bootloader/sdcard.c +++ b/stm32/mk4-bootloader/sdcard.c @@ -123,7 +123,11 @@ sdcard_probe(uint32_t *num_blocks) bool sdcard_is_inserted(void) { - return !!HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_13); +#ifdef FOR_Q1_ONLY + return !!HAL_GPIO_ReadPin(GPIOD, GPIO_PIN_3); // PD3 +#else + return !!HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_13); // PC13 +#endif } // dfu_hdr_parse() diff --git a/stm32/q1-bootloader/gpio.c b/stm32/q1-bootloader/gpio.c index fc3619d7..c3b29036 100644 --- a/stm32/q1-bootloader/gpio.c +++ b/stm32/q1-bootloader/gpio.c @@ -63,9 +63,9 @@ gpio_setup(void) } { // Port B - mostly unused, but want TEAR input - // TEAR from LCD: PB15 + // TEAR from LCD: PB11 GPIO_InitTypeDef setup = { - .Pin = GPIO_PIN_15, + .Pin = GPIO_PIN_11, .Mode = GPIO_MODE_INPUT, .Pull = GPIO_NOPULL, .Speed = GPIO_SPEED_FREQ_LOW, // 60Hz @@ -79,20 +79,22 @@ gpio_setup(void) // SD1 active LED: PC7 // USB active LED: PC6 // TURN OFF: PC0 + // SD mux: PC13 { GPIO_InitTypeDef setup = { - .Pin = GPIO_PIN_7 | GPIO_PIN_6 | GPIO_PIN_0, + .Pin = GPIO_PIN_7 | GPIO_PIN_6 | GPIO_PIN_0, GPIO_PIN_13, .Mode = GPIO_MODE_OUTPUT_PP, .Pull = GPIO_NOPULL, .Speed = GPIO_SPEED_FREQ_LOW, }; - HAL_GPIO_WritePin(GPIOC, GPIO_PIN_0, 0); // stay on! + HAL_GPIO_WritePin(GPIOC, GPIO_PIN_0, 0); // keep power on! HAL_GPIO_Init(GPIOC, &setup); - HAL_GPIO_WritePin(GPIOC, GPIO_PIN_7|GPIO_PIN_6, 0); // turn LEDs off + // turn LEDs off, SD mux to A + HAL_GPIO_WritePin(GPIOC, GPIO_PIN_7|GPIO_PIN_6|GPIO_PIN_13, 0); } // Port C - Inputs - // SD card detect switch: PC13, PC1 battery/not + // SD card detect switch: PC1 battery/not { GPIO_InitTypeDef setup = { .Pin = GPIO_PIN_13 | GPIO_PIN_1, .Mode = GPIO_MODE_INPUT, @@ -104,32 +106,44 @@ gpio_setup(void) // Port D - outputs // SD2 active LED: PD0 - // SD_MUX: PD3 { GPIO_InitTypeDef setup = { - .Pin = GPIO_PIN_0 | GPIO_PIN_3, + .Pin = GPIO_PIN_0, .Mode = GPIO_MODE_OUTPUT_PP, .Pull = GPIO_NOPULL, .Speed = GPIO_SPEED_FREQ_LOW, }; HAL_GPIO_Init(GPIOD, &setup); - HAL_GPIO_WritePin(GPIOD, GPIO_PIN_0|GPIO_PIN_3, 0); // turn off / select A slot + HAL_GPIO_WritePin(GPIOD, GPIO_PIN_0, 0); // turn off + } + + // Port D - Inputs + // SD slots detects: PD3/4 + { GPIO_InitTypeDef setup = { + .Pin = GPIO_PIN_3 | GPIO_PIN_4, + .Mode = GPIO_MODE_INPUT, + .Pull = GPIO_PULLUP, // required + .Speed = GPIO_SPEED_FREQ_LOW, + }; + HAL_GPIO_Init(GPIOD, &setup); } // Port E - Q1 things - // QR_RESET/TRIG - leave for now + // QR_RESET/TRIG - ignore for now // BL_ENABLE: PE3 // NFC_ACTIVE: PE4 (led) + // GPU control: 2,5,6 outputs { GPIO_InitTypeDef setup = { - .Pin = GPIO_PIN_3 | GPIO_PIN_4, + .Pin = GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_2 | GPIO_PIN_5 | GPIO_PIN_6, .Mode = GPIO_MODE_OUTPUT_PP, .Pull = GPIO_NOPULL, .Speed = GPIO_SPEED_FREQ_LOW, }; HAL_GPIO_Init(GPIOE, &setup); - HAL_GPIO_WritePin(GPIOE, GPIO_PIN_4, 0); // turn off NFC LED - HAL_GPIO_WritePin(GPIOE, GPIO_PIN_3, 1); // turn on Backlight + // turn off NFC LED, reset GPU, keep in reset + HAL_GPIO_WritePin(GPIOE, GPIO_PIN_4|GPIO_PIN_5, 0); + HAL_GPIO_WritePin(GPIOE, GPIO_PIN_3, 1); // turn on Backlight, } diff --git a/stm32/q1-bootloader/lcd.c b/stm32/q1-bootloader/lcd.c index 90567a0c..a8277ab3 100644 --- a/stm32/q1-bootloader/lcd.c +++ b/stm32/q1-bootloader/lcd.c @@ -18,9 +18,9 @@ //#define DISABLE_LCD // LCD connections: -// - all on port A +// - mostly on port A // - all push/pull outputs -// - PB15: TEAR input +// - shared with GPU // #define RESET_PIN GPIO_PIN_6 #define DC_PIN GPIO_PIN_8 @@ -28,6 +28,9 @@ #define SPI_SCK GPIO_PIN_5 #define SPI_MOSI GPIO_PIN_7 +// port B +#define TEAR_PIN GPIO_PIN_11 + const int LCD_WIDTH = 320; const int LCD_HEIGHT = 240; const int NUM_PIXELS = (LCD_WIDTH*LCD_HEIGHT); @@ -55,11 +58,15 @@ static SPI_HandleTypeDef spi_port; #endif static inline void wait_vsync(void) { - // PB15 is TEAR input: a positive pulse every 60Hz that + // PB11 is TEAR input: a positive pulse every 60Hz that // corresponds to vertical blanking time - while(HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_15) == 0) { - ; + uint32_t timeout = 1000000; + for(; timeout; timeout--) { + if(HAL_GPIO_ReadPin(GPIOB, TEAR_PIN) != 0) { + return; + } } + puts("TEAR timeout"); } // forward refs