diff options
author | root <root@no.no.james.local> | 2015-09-07 23:40:11 +0100 |
---|---|---|
committer | root <root@no.no.james.local> | 2015-09-07 23:40:11 +0100 |
commit | 8f7b23cea60eca5b359897bfc21ed84eb11a7bb5 (patch) | |
tree | 49810ddc616fcce444176b2ff181600f82840ae6 | |
parent | b83365010e8338a41988426f879243208714c44f (diff) | |
download | bracelet-8f7b23cea60eca5b359897bfc21ed84eb11a7bb5.tar.gz bracelet-8f7b23cea60eca5b359897bfc21ed84eb11a7bb5.tar.bz2 bracelet-8f7b23cea60eca5b359897bfc21ed84eb11a7bb5.zip |
fish
-rw-r--r-- | crypto/Makefile | 3 | ||||
-rw-r--r-- | crypto/gt22l16a1y.c | 109 | ||||
-rw-r--r-- | crypto/main.c | 3 | ||||
-rw-r--r-- | crypto/project.h | 46 | ||||
-rw-r--r-- | crypto/prototypes.h | 6 | ||||
-rw-r--r-- | crypto/rng.c | 24 | ||||
-rw-r--r-- | crypto/ssd1306.c | 24 | ||||
-rw-r--r-- | docs/GT22L16A1Y_V3.2.pdf | bin | 0 -> 3483966 bytes | |||
-rw-r--r-- | reverse_engineering/pinmap | 16 |
9 files changed, 202 insertions, 29 deletions
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<<SCLK); + NRF_GPIO->DIRCLR = (1 << MISO); + + NRF_GPIO->OUTSET = (1 << NCS) | (1<<MISO); +} + +void gt_read(uint32_t a,uint8_t * buf,size_t len) +{ + uint32_t c; + uint8_t v; + + NRF_GPIO->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<<MISO)) v|=c; + + + + NRF_GPIO->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 <stdint.h> #include <string.h> -#include <sdk/libraries/util/nordic_common.h> -#include <sdk/device/nrf.h> -#include <sdk/libraries/util/nrf_assert.h> -#include <sdk/libraries/util/app_error.h> -#include <sdk/drivers_nrf/hal/nrf_gpio.h> -#include <sdk/device/nrf51_bitfields.h> -#include <sdk/softdevice/s130/headers/ble.h> -#include <sdk/softdevice/s130/headers/ble_hci.h> + + + +#include <sdk/ble/common/ble_advdata.h> +#include <sdk/ble/common/ble_conn_params.h> #include <sdk/ble/common/ble_srv_common.h> + #include <sdk/ble/ble_advertising/ble_advertising.h> -#include <sdk/ble/common/ble_advdata.h> -#include <sdk/ble/ble_services/ble_hids/ble_hids.h> #include <sdk/ble/ble_services/ble_bas/ble_bas.h> #include <sdk/ble/ble_services/ble_dis/ble_dis.h> -#include <sdk/ble/common/ble_conn_params.h> -#include "bsp/bsp.h" +#include <sdk/ble/ble_services/ble_hids/ble_hids.h> +#include <sdk/ble/device_manager/device_manager.h> + +#include <sdk/device/nrf.h> +#include <sdk/device/nrf51_bitfields.h> + +#include <sdk/drivers_nrf/hal/nrf_gpio.h> +#include <sdk/drivers_nrf/hal/nrf_delay.h> +#include <sdk/drivers_nrf/pstorage/pstorage.h> +#include <sdk/drivers_nrf/rng/nrf_drv_rng.h> + +#include <sdk/libraries/button/app_button.h> #include <sdk/libraries/sensorsim/sensorsim.h> -#include "bsp/bsp_btn_ble.h" #include <sdk/libraries/scheduler/app_scheduler.h> -#include <sdk/softdevice/common/softdevice_handler/softdevice_handler_appsh.h> #include <sdk/libraries/timer/app_timer_appsh.h> -#include <sdk/ble/device_manager/device_manager.h> -#include <sdk/libraries/button/app_button.h> -#include <sdk/drivers_nrf/pstorage/pstorage.h> #include <sdk/libraries/trace/app_trace.h> -#include <sdk/drivers_nrf/hal/nrf_delay.h> +#include <sdk/libraries/util/app_error.h> +#include <sdk/libraries/util/nordic_common.h> +#include <sdk/libraries/util/nrf_assert.h> +#include <sdk/softdevice/common/softdevice_handler/softdevice_handler_appsh.h> +#include <sdk/softdevice/s130/headers/ble.h> +#include <sdk/softdevice/s130/headers/ble_hci.h> + + +#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<available) ? size : available; + err_code = nrf_drv_rng_rand(p_buff,length); + APP_ERROR_CHECK(err_code); + return length; +} + + +void rng_init(void) +{ + uint32_t err_code; + err_code = nrf_drv_rng_init(NULL); + APP_ERROR_CHECK(err_code); +} diff --git a/crypto/ssd1306.c b/crypto/ssd1306.c index 95cab2d..7421669 100644 --- a/crypto/ssd1306.c +++ b/crypto/ssd1306.c @@ -14,7 +14,7 @@ static void i2c_delay () { - nrf_delay_us (10000); + nrf_delay_us (1); } static void @@ -306,9 +306,27 @@ sd_on (void) void sd_doodle (void) { - static uint8_t i; + static uint8_t d[8]; + random_vector_generate(d,1); + uint32_t a; - sd_dat (i++); + + a=d[0]; + a%=63; + a*=8; + a+=768; + + gt_read(a,d,sizeof(d)); + + + sd_dat (d[0]); + sd_dat (d[1]); + sd_dat (d[2]); + sd_dat (d[3]); + sd_dat (d[4]); + sd_dat (d[5]); + sd_dat (d[6]); + sd_dat (d[7]); } diff --git a/docs/GT22L16A1Y_V3.2.pdf b/docs/GT22L16A1Y_V3.2.pdf Binary files differnew file mode 100644 index 0000000..fdebbf8 --- /dev/null +++ b/docs/GT22L16A1Y_V3.2.pdf diff --git a/reverse_engineering/pinmap b/reverse_engineering/pinmap index b7692e9..bbc0601 100644 --- a/reverse_engineering/pinmap +++ b/reverse_engineering/pinmap @@ -149,11 +149,11 @@ G chip . 1 2 3 4 -1 -> 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 |