1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-26 17:38:39 +00:00

trezorhal: add io.SBU

This commit is contained in:
Pavol Rusnak 2017-09-07 23:50:57 +02:00
parent b715f7463d
commit a67be06349
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
6 changed files with 122 additions and 0 deletions

View File

@ -278,6 +278,7 @@ SOURCE_TREZORHAL = [
'embed/trezorhal/flash.c', 'embed/trezorhal/flash.c',
'embed/trezorhal/mini_printf.c', 'embed/trezorhal/mini_printf.c',
'embed/trezorhal/rng.c', 'embed/trezorhal/rng.c',
'embed/trezorhal/sbu.c',
'embed/trezorhal/sdcard.c', 'embed/trezorhal/sdcard.c',
'embed/trezorhal/stm32_it.c', 'embed/trezorhal/stm32_it.c',
'embed/trezorhal/stm32_system.c', 'embed/trezorhal/stm32_system.c',

View File

@ -0,0 +1,54 @@
/*
* Copyright (c) Pavol Rusnak, SatoshiLabs
*
* Licensed under TREZOR License
* see LICENSE file for details
*/
#if defined TREZOR_STM32
#include "sbu.h"
#elif defined TREZOR_UNIX
#include "unix-sbu-mock.h"
#else
#error Unsupported TREZOR port. Only STM32 and UNIX ports are supported.
#endif
/// class SBU:
/// '''
/// '''
typedef struct _mp_obj_SBU_t {
mp_obj_base_t base;
} mp_obj_SBU_t;
/// def __init__(self) -> None:
/// '''
/// '''
STATIC mp_obj_t mod_trezorio_SBU_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
mp_arg_check_num(n_args, n_kw, 0, 0, false);
mp_obj_SBU_t *o = m_new_obj(mp_obj_SBU_t);
o->base.type = type;
sbu_init();
return MP_OBJ_FROM_PTR(o);
}
/// def set(self, sbu1: bool, sbu2: bool) -> None:
/// '''
/// Sets SBU wires to sbu1 and sbu2 values respectively
/// '''
STATIC mp_obj_t mod_trezorio_SBU_set(mp_obj_t self, mp_obj_t sbu1, mp_obj_t sbu2) {
sbu_set(mp_obj_is_true(sbu1), mp_obj_is_true(sbu2));
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorio_SBU_set_obj, mod_trezorio_SBU_set);
STATIC const mp_rom_map_elem_t mod_trezorio_SBU_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_set), MP_ROM_PTR(&mod_trezorio_SBU_set_obj) },
};
STATIC MP_DEFINE_CONST_DICT(mod_trezorio_SBU_locals_dict, mod_trezorio_SBU_locals_dict_table);
STATIC const mp_obj_type_t mod_trezorio_SBU_type = {
{ &mp_type_type },
.name = MP_QSTR_SBU,
.make_new = mod_trezorio_SBU_make_new,
.locals_dict = (void*)&mod_trezorio_SBU_locals_dict,
};

View File

@ -11,12 +11,15 @@
#if MICROPY_PY_TREZORIO #if MICROPY_PY_TREZORIO
#include "modtrezorio-sbu.h"
#include "modtrezorio-sdcard.h" #include "modtrezorio-sdcard.h"
#include "modtrezorio-msg.h" #include "modtrezorio-msg.h"
STATIC const mp_rom_map_elem_t mp_module_trezorio_globals_table[] = { STATIC const mp_rom_map_elem_t mp_module_trezorio_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_trezorio) }, { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_trezorio) },
{ MP_ROM_QSTR(MP_QSTR_SBU), MP_ROM_PTR(&mod_trezorio_SBU_type) },
{ MP_ROM_QSTR(MP_QSTR_SDCard), MP_ROM_PTR(&mod_trezorio_SDCard_type) }, { MP_ROM_QSTR(MP_QSTR_SDCard), MP_ROM_PTR(&mod_trezorio_SDCard_type) },
{ MP_ROM_QSTR(MP_QSTR_USB), MP_ROM_PTR(&mod_trezorio_USB_type) }, { MP_ROM_QSTR(MP_QSTR_USB), MP_ROM_PTR(&mod_trezorio_USB_type) },

View File

@ -0,0 +1,17 @@
/*
* Copyright (c) Pavol Rusnak, SatoshiLabs
*
* Licensed under TREZOR License
* see LICENSE file for details
*/
#include "../../trezorhal/sbu.h"
int sbu_init(void)
{
return 0;
}
void sbu_set(bool sbu1, bool sbu2)
{
}

31
embed/trezorhal/sbu.c Normal file
View File

@ -0,0 +1,31 @@
/*
* Copyright (c) Pavol Rusnak, SatoshiLabs
*
* Licensed under TREZOR License
* see LICENSE file for details
*/
#include STM32_HAL_H
#include "sbu.h"
int sbu_init(void) {
GPIO_InitTypeDef GPIO_InitStructure;
// SBU1/PA2 SBU2/PA3
GPIO_InitStructure.Pin = GPIO_PIN_2 | GPIO_PIN_3;
GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStructure.Pull = GPIO_NOPULL;
GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_2, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_3, GPIO_PIN_RESET);
return 0;
}
void sbu_set(bool sbu1, bool sbu2) {
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_2, sbu1 ? GPIO_PIN_SET : GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_3, sbu2 ? GPIO_PIN_SET : GPIO_PIN_RESET);
}

16
embed/trezorhal/sbu.h Normal file
View File

@ -0,0 +1,16 @@
/*
* Copyright (c) Pavol Rusnak, SatoshiLabs
*
* Licensed under TREZOR License
* see LICENSE file for details
*/
#ifndef __TREZORHAL_SBU_H__
#define __TREZORHAL_SBU_H__
#include <stdbool.h>
int sbu_init(void);
void sbu_set(bool sbu1, bool sbu2);
#endif