void N6100LCD::set_pixel(uint8_t x, uint8_t y, uint16_t color) { set_area(x, y, x, y); spi_data((color >> 4) & 0xFF); spi_data(((color & 0x0F) << 4)); spi_cmd(NOP); spi_flush(); }
void wm8737_spi_init(void) { LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 11); /* Set DSS data to 16-bit, Frame format SPI, CPOL = 1, CPHA = 1, and SCR is 0 */ LPC_SPI0->CR0 = 0x00CF; /* This mode is rising-edge sampled, which is what the ADC wants. */ /* SSPCPSR clock prescale register, master mode, minimum divisor is 0x02 */ LPC_SPI0->CPSR = 0x2; /* This gives a clock rate of 6MHz! */ spi_flush(); }
void N6100LCD::draw_hline(uint16_t c, uint8_t x, uint8_t y, uint8_t width) { if (width<1 || width>ROW_LENGTH) return; set_area(x, y, x+width-1, y); for (uint8_t i=0; i<width; ) { i += 2; spi_data(( c&0xFF0)>>4); // R1G1 spi_data(((c&0x00F)<<4)|((c&0xF00)>>8)); // B1R2 spi_data( c&0x0FF ); // G2B2 } spi_flush(); }
void do_sampling(void) { /* ADC LR Clock on P0[2], rising edge is trigger */ LPC_IOCON->PIO0_2 &= ~0x07; /* GPIO */ LPC_GPIO0->MASKED_ACCESS[1<<2] = (0<<2); /* Low to start */ LPC_GPIO0->DIR |= (1<<2); /* Output */ /* Setup SPI for the ADC transfer */ wm8737_spi_init(); wm8737_spi_on(); /** * Disable all interrupts - Be careful that the watchdog * calibration timer doesn't occur during this period */ __disable_irq(); /* We need to use a function pointer to jump our execution to RAM */ sampling_func sampling_ptr = sampling; /* Prepare for the sampling loop */ sampling_index = 0; /* Let RAM accesses settle down before we jump */ __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); /* Actually take the sample */ sampling_ptr(); LPC_GPIO0->MASKED_ACCESS[1<<2] = (1<<2); /* P0[2] = ADCLRCLK */ /* Tidy up from the sampling run */ spi_flush(); /* Re-enable all interrupts */ __enable_irq(); /* Return the SPI to how it was before */ wm8737_spi_off(); /** * Revert the SPI bus to working for the radio. */ radio_spi_init(); }
void writeData(uint8_t d) { if (!g_HWSPI) { bbData(d); return; } memory_barrier(); gpio_set(PIN_DC); gpio_clear(24); memory_barrier(); pack.command = 0x100 | d; // LoSSI 9-bit Parameter mode spi_start(0); // Start SPI transfer to CS0 destination // Bypass spi_write function here //while (!HW.SPI0.CS.B.TXD); // ensure no reads //HW.SPI0.FIFO = pack.command; spi_write(d); spi_flush(); memory_barrier(); gpio_set(24); memory_barrier(); //printf("Data:%.2X \n",pack.command); }
void writeCommand(uint8_t c) { if (!g_HWSPI) { bbCmd(c); return; } memory_barrier(); gpio_clear(PIN_DC); gpio_clear(24); memory_barrier(); pack.command = 0x000 | c; // LoSSI 9-bit Command mode spi_start(0); // Start SPI transfer to CS0 destination // Bypass spi_write function here //while (!HW.SPI0.CS.B.TXD); // ensure no reads //HW.SPI0.FIFO = pack.command; spi_write(c) ; spi_flush(); memory_barrier(); gpio_set(24); memory_barrier(); printf("Command:%.2X ",pack.command); }
int N6100LCD::init(void) { if (MAP_FAILED==gpio_ && gpio_init() < 0) { DBG("gpio init failed\n"); return -1; } if (spi_ < 0 && spi_init() < 0) { DBG("spi init failed\n"); return -1; } DBG("gpio = %X\n", gpio_); DBG("spi = %d\n", spi_); INP_GPIO(rst_); OUT_GPIO(rst_); GPIO_CLR(rst_); usleep(200*1000); GPIO_SET(rst_); usleep(200*1000); if (type_ == TYPE_EPSON) { spi_cmd(DISCTL); // Display control (0xCA) spi_data(0x0C); // 12 = 1100 - CL dividing ratio [don't divide] switching period 8H (default) spi_data(0x20); // nlines/4 - 1 = 132/4 - 1 = 32 duty spi_data(0x00); // No inversely highlighted lines spi_cmd(COMSCN); // common scanning direction (0xBB) spi_data(0x01); // 1->68, 132<-69 scan direction spi_cmd(OSCON); // internal oscialltor ON (0xD1) spi_cmd(SLPOUT); // sleep out (0x94) spi_cmd(PWRCTR); // power ctrl (0x20) spi_data(0x0F); // everything on, no external reference resistors spi_cmd(DISINV); // invert display mode (0xA7) spi_cmd(DATCTL); // data control (0xBC) spi_data(0x03); // Inverse page address, reverse rotation column address, column scan-direction !!! try 0x01 spi_data(0x00); // normal RGB arrangement spi_data(0x02); // 16-bit Grayscale Type A (12-bit color) spi_cmd(VOLCTR); // electronic volume, this is the contrast/brightness (0x81) spi_data(32); // volume (contrast) setting - fine tuning, original (0-63) spi_data(3); // internal resistor ratio - coarse adjustment (0-7) spi_cmd(NOP); usleep(100 * 1000); spi_cmd(DISON); // display on (0xAF) } else if (type_ == TYPE_PHILIPS) { spi_cmd(SLEEPOUT); // Sleep Out (0x11) spi_cmd(BSTRON); // Booster voltage on (0x03) spi_cmd(DISPON); // Display on (0x29) //spi_cmd(INVON); // Inversion on (0x20) // 12-bit color pixel format: spi_cmd(COLMOD); // Color interface format (0x3A) spi_data(0x03); // 0b011 is 12-bit/pixel mode spi_cmd(MADCTL); // Memory Access Control(PHILLIPS) //spi_data(0x08); spi_data(0xC0); spi_cmd(SETCON); // Set Contrast(PHILLIPS) spi_data(0x3E); spi_cmd(NOPP); // nop(PHILLIPS) } spi_flush(); DBG("lcd init ok\n"); return 0; }
void N6100LCD::spi_word(uint16_t word) { *pbuff++ = word; if(++buffsz >= SPI_BUFF_SIZE) spi_flush(); }