From 8f7b23cea60eca5b359897bfc21ed84eb11a7bb5 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 7 Sep 2015 23:40:11 +0100 Subject: fish --- crypto/Makefile | 3 ++ crypto/gt22l16a1y.c | 109 +++++++++++++++++++++++++++++++++++++++++++++ crypto/main.c | 3 ++ crypto/project.h | 46 +++++++++++-------- crypto/prototypes.h | 6 +++ crypto/rng.c | 24 ++++++++++ crypto/ssd1306.c | 24 ++++++++-- docs/GT22L16A1Y_V3.2.pdf | Bin 0 -> 3483966 bytes reverse_engineering/pinmap | 16 +++---- 9 files changed, 202 insertions(+), 29 deletions(-) create mode 100644 crypto/gt22l16a1y.c create mode 100644 crypto/rng.c create mode 100644 docs/GT22L16A1Y_V3.2.pdf diff --git a/crypto/Makefile b/crypto/Makefile index 5494a9f..524d603 100644 --- a/crypto/Makefile +++ b/crypto/Makefile @@ -28,6 +28,7 @@ SDKCSRCS= \ drivers_nrf/gpiote/nrf_drv_gpiote.c \ drivers_nrf/pstorage/pstorage.c \ drivers_nrf/hal/nrf_delay.c \ + drivers_nrf/rng/nrf_drv_rng.c \ libraries/uart/retarget.c \ libraries/util/app_error.c \ libraries/util/nrf_assert.c \ @@ -52,6 +53,8 @@ SDKSSRCS = toolchain/gcc/gcc_startup_nrf51.s PROTOSRCS= \ ssd1306.c \ + rng.c \ + gt22l16a1y.c \ main.c CSRCS = \ diff --git a/crypto/gt22l16a1y.c b/crypto/gt22l16a1y.c new file mode 100644 index 0000000..b997c36 --- /dev/null +++ b/crypto/gt22l16a1y.c @@ -0,0 +1,109 @@ +#include "project.h" + +#define SCLK 17 +#define MOSI 18 +#define NCS 19 +#define MISO 20 + +#define READ 0x3 +#define FAST_READ 0xb + + +static inline void d(void) +{ +nrf_delay_us(1); +} + +void +gt_init (void) +{ + NRF_GPIO->PIN_CNF[SCLK] = + (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) | + (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos) | + (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos) | + (GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos) | + (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos); + + NRF_GPIO->PIN_CNF[MOSI] = + (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) | + (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos) | + (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos) | + (GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos) | + (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos); + + + NRF_GPIO->PIN_CNF[NCS] = + (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) | + (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos) | + (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos) | + (GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos) | + (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos); + + + + NRF_GPIO->PIN_CNF[MISO] = + (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) | + (GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos) | + (GPIO_PIN_CNF_PULL_Pulldown << GPIO_PIN_CNF_PULL_Pos) | + (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | + (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos); + + + NRF_GPIO->DIRSET = (1 << MOSI) | (1 << NCS) | (1<DIRCLR = (1 << MISO); + + NRF_GPIO->OUTSET = (1 << NCS) | (1<OUTCLR = (1 << SCLK); + d(); + NRF_GPIO->OUTCLR = (1 << NCS); + NRF_GPIO->OUTSET = (1 << NCS); + d(); + + a |= READ << 24; + + a=0x3000000; + a+=768+80; + + for (c=0x80000000;c;c>>=1) { + if (c&a) + NRF_GPIO->OUTSET = (1 << MOSI); + else + NRF_GPIO->OUTCLR = (1 << MOSI); + d(); + + NRF_GPIO->OUTSET = (1 << SCLK); + d(); + NRF_GPIO->OUTCLR = (1 << SCLK); + d(); + } + + while (len--) { + v=0; + for (c=0x80;c;c>>=1) { + if (NRF_GPIO->IN & (1<OUTSET = (1 << SCLK); + d(); + NRF_GPIO->OUTCLR = (1 << SCLK); + d(); + } + *(buf++)=v; + } + + d(); + + NRF_GPIO->OUTSET = (1 << NCS); + d(); + + +} + diff --git a/crypto/main.c b/crypto/main.c index 4f15694..bab09ab 100644 --- a/crypto/main.c +++ b/crypto/main.c @@ -1476,6 +1476,9 @@ int main(void) conn_params_init(); buffer_init(); + rng_init(); + gt_init(); + sd_init(); sd_on(); diff --git a/crypto/project.h b/crypto/project.h index cf6fac0..79deb31 100644 --- a/crypto/project.h +++ b/crypto/project.h @@ -1,32 +1,42 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include + + + +#include +#include #include + #include -#include -#include #include #include -#include -#include "bsp/bsp.h" +#include +#include + +#include +#include + +#include +#include +#include +#include + +#include #include -#include "bsp/bsp_btn_ble.h" #include -#include #include -#include -#include -#include #include -#include +#include +#include +#include +#include +#include +#include + + +#include "bsp/bsp.h" +#include "bsp/bsp_btn_ble.h" #include "prototypes.h" diff --git a/crypto/prototypes.h b/crypto/prototypes.h index 35c8abe..ddff112 100644 --- a/crypto/prototypes.h +++ b/crypto/prototypes.h @@ -2,6 +2,12 @@ extern void sd_on(void); extern void sd_doodle(void); extern void sd_init(void); +/* rng.c */ +extern uint8_t random_vector_generate(uint8_t *p_buff, uint8_t size); +extern void rng_init(void); +/* gt22l16a1y.c */ +extern void gt_init(void); +extern void gt_read(uint32_t a, uint8_t *buf, size_t len); /* main.c */ extern void assert_nrf_callback(uint16_t line_num, const uint8_t *p_file_name); extern int main(void); diff --git a/crypto/rng.c b/crypto/rng.c new file mode 100644 index 0000000..779a106 --- /dev/null +++ b/crypto/rng.c @@ -0,0 +1,24 @@ +#include "project.h" + + + + +uint8_t random_vector_generate(uint8_t * p_buff, uint8_t size) +{ + uint8_t available; + uint32_t err_code; + err_code = nrf_drv_rng_bytes_available(&available); + APP_ERROR_CHECK(err_code); + uint8_t length = (size GND -2 -> ? -3 -> P0.18 -4 -> P0.17 -5 -> pulled up -6 -> VCC -7 -> P0.19 -8 -> P0.20 +1 -> GND GND +2 -> ? GND +3 -> P0.18 MOSI +4 -> P0.17 SCLK +5 -> pulled up HOLD# +6 -> VCC VCC +7 -> P0.19 CS# +8 -> P0.20 MISO -- cgit v1.2.3