Skip to content
This repository has been archived by the owner on May 28, 2019. It is now read-only.

Commit

Permalink
trezorhal: turn sdcard/cpt circuitry on/off using PC0/PB10 pin
Browse files Browse the repository at this point in the history
  • Loading branch information
prusnak committed Jul 11, 2018
1 parent dca61a4 commit 6ce106b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
Binary file modified docs/hardware/schematic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 30 additions & 3 deletions embed/trezorhal/sdcard.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@

static SD_HandleTypeDef sd_handle;

static void sdcard_default_pin_state(void) {
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_0, GPIO_PIN_SET); // SD_ON/PC0
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_8, GPIO_PIN_RESET); // SD_DAT0/PC8
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_9, GPIO_PIN_RESET); // SD_DAT1/PC9
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_10, GPIO_PIN_RESET); // SD_DAT2/PC10
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_11, GPIO_PIN_RESET); // SD_DAT3/PC11
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_12, GPIO_PIN_RESET); // SD_CLK/PC12
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET); // SD_CMD/PD2
}

void sdcard_init(void) {
// invalidate the sd_handle
sd_handle.Instance = NULL;
Expand All @@ -68,11 +78,20 @@ void sdcard_init(void) {
HAL_GPIO_Init(GPIOD, &GPIO_InitStructure);

// configure the SD card detect pin
GPIO_InitStructure.Mode = GPIO_MODE_INPUT;
GPIO_InitStructure.Pull = GPIO_PULLUP;
GPIO_InitStructure.Mode = GPIO_MODE_INPUT;
GPIO_InitStructure.Pull = GPIO_PULLUP;
GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStructure.Pin = GPIO_PIN_13;
HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);

// configure the SD card circuitry on/off pin
GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStructure.Pull = GPIO_NOPULL;
GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStructure.Pin = GPIO_PIN_13;
GPIO_InitStructure.Pin = GPIO_PIN_0;
HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);

sdcard_default_pin_state();
}

void HAL_SD_MspInit(SD_HandleTypeDef *hsd) {
Expand All @@ -90,6 +109,10 @@ secbool sdcard_is_present(void) {
}

secbool sdcard_power_on(void) {
// turn on SD card circuitry
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_0, GPIO_PIN_RESET); // SD_ON/PC0
HAL_Delay(50);

if (sectrue != sdcard_is_present()) {
return secfalse;
}
Expand Down Expand Up @@ -133,6 +156,10 @@ void sdcard_power_off(void) {
}
HAL_SD_DeInit(&sd_handle);
sd_handle.Instance = NULL;

// turn off SD card circuitry
HAL_Delay(50);
sdcard_default_pin_state();
}

uint64_t sdcard_get_capacity_in_bytes(void) {
Expand Down
10 changes: 10 additions & 0 deletions embed/trezorhal/touch.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ void touch_init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;

// configure the CTP circuitry on/off pin
GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStructure.Pull = GPIO_NOPULL;
GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStructure.Pin = GPIO_PIN_10;
HAL_GPIO_Init(GPIOB, &GPIO_InitStructure);

HAL_GPIO_WritePin(GPIOB, GPIO_PIN_10, GPIO_PIN_RESET); // CTP_ON/PB10
HAL_Delay(50);

// Enable I2C clock
__HAL_RCC_I2C1_CLK_ENABLE();

Expand Down

0 comments on commit 6ce106b

Please sign in to comment.