Initialize the display controller on an SPI bus
| 239 | // Initialize the display controller on an SPI bus |
| 240 | // |
| 241 | void obdSPIInit(OBDISP *pOBD, int iType, int iDC, int iCS, int iReset, int iMOSI, int iCLK, int iLED, int bFlip, int bInvert, int bBitBang, int32_t iSpeed) |
| 242 | { |
| 243 | uint8_t uc[32], *s; |
| 244 | int iLen; |
| 245 | |
| 246 | pOBD->ucScreen = NULL; // start with no backbuffer; user must provide one later |
| 247 | pOBD->iDCPin = iDC; |
| 248 | pOBD->iCSPin = iCS; |
| 249 | pOBD->iMOSIPin = iMOSI; |
| 250 | pOBD->iCLKPin = iCLK; |
| 251 | pOBD->iLEDPin = iLED; |
| 252 | pOBD->type = iType; |
| 253 | pOBD->flip = bFlip; |
| 254 | pOBD->invert = bInvert; |
| 255 | pOBD->wrap = 0; // default - disable text wrap |
| 256 | pOBD->com_mode = COM_SPI; // communication mode |
| 257 | |
| 258 | gpio_set_dir(pOBD->iCSPin, true); |
| 259 | gpio_put(pOBD->iCSPin, 0); //(pOBD->type < SHARP_144x168)); // set to not-active |
| 260 | |
| 261 | if (pOBD->iDCPin != 0xff) // Note - not needed on Sharp Memory LCDs |
| 262 | { |
| 263 | gpio_set_dir(pOBD->iDCPin, true); |
| 264 | gpio_put(pOBD->iDCPin, 0); // for some reason, command mode must be set or some OLEDs/LCDs won't initialize correctly even if set later |
| 265 | } |
| 266 | |
| 267 | if (bBitBang) |
| 268 | { |
| 269 | gpio_set_dir(iMOSI, true); |
| 270 | gpio_set_dir(iCLK, true); |
| 271 | } |
| 272 | |
| 273 | // Reset it |
| 274 | if (iReset != -1) |
| 275 | { |
| 276 | gpio_set_dir(iReset, true); |
| 277 | gpio_put(iReset, LOW); |
| 278 | sleep_ms(100); |
| 279 | gpio_put(iReset, HIGH); |
| 280 | sleep_ms(100); |
| 281 | } |
| 282 | |
| 283 | if (iLED != -1) |
| 284 | { |
| 285 | gpio_set_dir(iLED, true); |
| 286 | } |
| 287 | |
| 288 | // Initialize SPI |
| 289 | if (!bBitBang) |
| 290 | { |
| 291 | pOBD->iMOSIPin = 0xff; // mark it as hardware SPI |
| 292 | gpio_set_function(pOBD->iCLKPin, GPIO_FUNC_SPI); |
| 293 | gpio_set_function(pOBD->iMOSIPin, GPIO_FUNC_SPI); |
| 294 | |
| 295 | spi_init(pOBD->spi->getController(), 1000 * 1000); |
| 296 | spi_set_format(pOBD->spi->getController(), 8, SPI_CPOL_0, SPI_CPHA_0, SPI_MSB_FIRST); |
| 297 | } |
| 298 |
nothing calls this directly
no test coverage detected