Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 6 | mjames | 1 | #include "ch.h" |
| 2 | #include "hal.h" |
||
| 3 | |||
| 4 | #include "spiInterface.h" |
||
| 5 | |||
| 6 | void ssd1306spiInit(void) { |
||
| 7 | static const SPIConfig spiConfig = { |
||
| 8 | .ssport = SPI_CS_GPIO, |
||
| 9 | .sspad = SPI_CS_PIN, |
||
| 10 | .cr1 = SPI_CR1_MSTR |
||
| 11 | | SPI_CR1_CPOL |
||
| 12 | | SPI_CR1_CPHA |
||
| 13 | | SPI_BaudRatePrescaler_4 |
||
| 14 | }; |
||
| 15 | // swap SP1 to the remapped pins ! |
||
| 16 | |||
| 17 | AFIO->MAPR |= AFIO_MAPR_SPI1_REMAP; |
||
| 18 | // release unused JTAG pins to application |
||
| 19 | AFIO->MAPR |= AFIO_MAPR_SWJ_CFG_JTAGDISABLE; |
||
| 20 | |||
| 21 | spiStart(&SPID1, &spiConfig); |
||
| 22 | } |
||
| 23 | |||
| 24 | void ssd1306fastSPIwrite(uint8_t c) { |
||
| 25 | // char c = d; |
||
| 26 | pal_lld_setport(SPI_CD_GPIO, 1 << SPI_CD_PIN); |
||
| 27 | spiSelect(&SPID1); |
||
| 28 | spiSend(&SPID1, 1, &c); |
||
| 29 | spiUnselect(&SPID1); |
||
| 30 | } |
||
| 31 | |||
| 32 | void ssd1306commandSPIwrite(uint8_t c) { |
||
| 33 | // char c = d; |
||
| 34 | pal_lld_clearport(SPI_CD_GPIO, 1 << SPI_CD_PIN); |
||
| 35 | spiSelect(&SPID1); |
||
| 36 | spiSend(&SPID1, 1, &c); |
||
| 37 | spiUnselect(&SPID1); |
||
| 38 | pal_lld_setport(SPI_CD_GPIO, 1 << SPI_CD_PIN); |
||
| 39 | } |
||
| 40 | |||
| 41 | void ssd1306resetDisplay(void) { |
||
| 42 | |||
| 43 | pal_lld_setport(SPI_RESET_GPIO, 1 << SPI_RESET_PIN); |
||
| 44 | // VDD (3.3V) goes high at start, lets just chill for a ms |
||
| 45 | chThdSleep(1); |
||
| 46 | // bring reset low |
||
| 47 | pal_lld_clearport(SPI_RESET_GPIO, 1 << SPI_RESET_PIN); |
||
| 48 | /// wait 10ms |
||
| 49 | chThdSleep(1); |
||
| 50 | // bring out of reset |
||
| 51 | pal_lld_setport(SPI_RESET_GPIO, 1 << SPI_RESET_PIN); |
||
| 52 | /// turn on VCC (9V?) |
||
| 53 | // set CD pin |
||
| 54 | pal_lld_setport(SPI_CD_GPIO, 1 << SPI_CD_PIN); |
||
| 55 | } |
||
| 56 | |||
| 57 | void ssd1306SendDisplay(uint8_t * buffer, uint8_t len) { |
||
| 58 | pal_lld_setport(SPI_CD_GPIO, 1 << SPI_CD_PIN); |
||
| 59 | spiSelect(&SPID1); |
||
| 60 | spiSend(&SPID1, len, buffer); |
||
| 61 | spiUnselect(&SPID1); |
||
| 62 | |||
| 63 | } |
||
| 64 |