static void wr_cmd(u08 reg, u08 param) { CS_ENABLE(); wr_spi(LCD_REGISTER); wr_spi(reg); CS_DISABLE(); CS_ENABLE(); wr_spi(LCD_DATA); wr_spi(param); CS_DISABLE(); }
void ADS7846_rd_data(void) { uint_least8_t p, a1, a2, b1, b2; uint_least16_t x, y; //SPI speed-down #if !defined(SOFTWARE_SPI) && (defined(__AVR__) || defined(ARDUINO_ARCH_AVR)) uint_least8_t spcr, spsr; spcr = SPCR; spsr = SPSR; #if F_CPU >= 8000000UL SPI.setClockDivider(SPI_CLOCK_DIV4); #else /* if F_CPU >= 4000000UL */ SPI.setClockDivider(SPI_CLOCK_DIV2); #endif #endif //get pressure CS_ENABLE(); ADS7846_wr_spi(CMD_START | CMD_8BIT | CMD_Z1_POS); p = ADS7846_rd_spi() & 0x7F; CS_DISABLE(); ADS7846_delay_ms(1); if (p > MIN_PRESSURE) { pressure = p; //get X data CS_ENABLE(); ADS7846_wr_spi(CMD_START | CMD_8BIT | CMD_X_POS); tp_x = ADS7846_rd_spi(); CS_DISABLE(); ADS7846_delay_ms(1); // get y CS_ENABLE(); ADS7846_wr_spi(CMD_START | CMD_8BIT | CMD_Y_POS); tp_y = ADS7846_rd_spi(); CS_DISABLE(); ADS7846_delay_ms(1); } else { pressure = 0; } //restore SPI settings #if !defined(SOFTWARE_SPI) && (defined(__AVR__) || defined(ARDUINO_ARCH_AVR)) SPCR = spcr; SPSR = spsr; #endif return; }
void S65L2F50::begin(uint_least8_t clock_div) { //init pins #if defined(RST_PIN) pinMode(RST_PIN, OUTPUT); RST_ENABLE(); #endif pinMode(CS_PIN, OUTPUT); pinMode(RS_PIN, OUTPUT); pinMode(CLK_PIN, OUTPUT); pinMode(MOSI_PIN, OUTPUT); CS_DISABLE(); #if !defined(SOFTWARE_SPI) SPI.setDataMode(SPI_MODE0); SPI.setBitOrder(MSBFIRST); SPI.setClockDivider(clock_div); SPI.begin(); #endif //reset display reset(clock_div); return; }
void ADS7846::begin(void) { //init pins pinMode(CS_PIN, OUTPUT); CS_DISABLE(); pinMode(CLK_PIN, OUTPUT); pinMode(MOSI_PIN, OUTPUT); pinMode(MISO_PIN, INPUT); #ifdef IRQ_PIN pinMode(IRQ_PIN, INPUT); digitalWrite(IRQ_PIN, HIGH); //pull-up #endif #ifdef BUSY_PIN pinMode(BUSY_PIN, INPUT); digitalWrite(BUSY_PIN, HIGH); //pull-up #endif #if !defined(SOFTWARE_SPI) SPI.setDataMode(SPI_MODE0); SPI.begin(); #endif //set vars tp_matrix.div = 0; tp_x = 0; tp_y = 0; tp_last_x = 0; tp_last_y = 0; lcd_x = 0; lcd_y = 0; pressure = 0; setOrientation(0); return; }
char SD_init() { char i; CS_DISABLE(); for (i = 0; i < 10; i++) SPI_transfer(0xFF); #ifdef DEBUG USART_printstr("\r\n"); #endif for (i = 0; i < 10 && SD_command(0x40, 0x00000000, 0x95, 8) != 1; i++) { _delay_ms(100); #ifndef DEBUG USART_printch('.'); #endif } if (i == 10) return -1; for (i = 0; i < 10 && SD_command(0x41, 0x00000000, 0xFF, 8) != 0; i++) { _delay_ms(100); #ifndef DEBUG USART_printch('.'); #endif } if (i == 10) return -2; SD_command(0x50, 0x00000200, 0xFF, 8); return 0; }
void MI0283QT2::begin(uint_least8_t clock_div) { //init pins #if defined(RST_PIN) pinMode(RST_PIN, OUTPUT); RST_ENABLE(); #endif pinMode(LED_PIN, OUTPUT); pinMode(CS_PIN, OUTPUT); pinMode(CLK_PIN, OUTPUT); pinMode(MOSI_PIN, OUTPUT); pinMode(MISO_PIN, INPUT); LED_DISABLE(); CS_DISABLE(); #if defined(ADS7846) pinMode(ADSCS_PIN, OUTPUT); ADSCS_DISABLE(); #endif #if !defined(SOFTWARE_SPI) SPI.setDataMode(SPI_MODE0); SPI.setBitOrder(MSBFIRST); SPI.setClockDivider(clock_div); SPI.begin(); #endif //reset display reset(clock_div); //enable backlight led(50); return; }
/*---------------------------------------------------------------------------------------*/ error_t fram_init(uint8_t spi_mode) { CSSEL &= ~(1 << CSPIN); /* I/O selected */ CSDIR |= (1 << CSPIN); CS_DISABLE(); VDDSEL &= ~(1 << VDDPIN); VDDDIR |= (1 << VDDPIN); VDD_ENABLE(); WPSEL &= ~(1 << WPPIN); /* I/O selected */ WPDIR |= (1 << WPPIN); WP_DISABLE(); usci_spi_init(spi_mode); /* Test SPI Operation */ uint8_t pDeviceID[4]; fram_readDeviceID(pDeviceID); if (pDeviceID[0] != 0x04 || pDeviceID[1] != 0x7F || pDeviceID[2] != 0x28 || pDeviceID[3] != 0x03) { return ERROR_INIT_FAIL; } return OK; }
void MI0283QT9::begin(uint_least8_t clock_div) { //init pins #if defined(RST_PIN) pinMode(RST_PIN, OUTPUT); RST_ENABLE(); #endif pinMode(LED_PIN, OUTPUT); pinMode(CS_PIN, OUTPUT); #if defined(LCD_8BIT_SPI) pinMode(RS_PIN, OUTPUT); RS_HIGH(); #endif pinMode(SCK_PIN, OUTPUT); pinMode(MOSI_PIN, OUTPUT); pinMode(MISO_PIN, INPUT); LED_DISABLE(); CS_DISABLE(); #if defined(ADS7846) pinMode(ADSCS_PIN, OUTPUT); ADSCS_DISABLE(); #endif #if !defined(SOFTWARE_SPI) lcd_clock_div = clock_div; SPI.setDataMode(SPI_MODE0); SPI.setBitOrder(MSBFIRST); //SPI.setClockDivider(clock_div); SPI.begin(); #endif //SPI speed-down #if !defined(SOFTWARE_SPI) # if F_CPU >= 128000000UL SPI.setClockDivider(SPI_CLOCK_DIV64); # elif F_CPU >= 64000000UL SPI.setClockDivider(SPI_CLOCK_DIV32); # elif F_CPU >= 32000000UL SPI.setClockDivider(SPI_CLOCK_DIV16); # elif F_CPU >= 16000000UL SPI.setClockDivider(SPI_CLOCK_DIV8); # else //elif F_CPU >= 8000000UL SPI.setClockDivider(SPI_CLOCK_DIV4); # endif #endif //reset display reset(); //SPI speed-up #if !defined(SOFTWARE_SPI) SPI.setClockDivider(clock_div); #endif //enable backlight led(50); return; }
static void wr_data(u16 data) { CS_ENABLE(); wr_spi(LCD_DATA); wr_spi(data>>8); wr_spi(data); CS_DISABLE(); }
void REDFLY::disable(void) //deselect module { flush(); read_state = 0; CS_DISABLE(); return; }
void display_reset(void) { //reset CS_DISABLE(); RST_ENABLE(); _delay_ms(50); RST_DISABLE(); _delay_ms(50); //driving ability wr_cmd(0xEA, 0x0000); wr_cmd(0xEB, 0x0020); wr_cmd(0xEC, 0x000C); wr_cmd(0xED, 0x00C4); wr_cmd(0xE8, 0x0040); wr_cmd(0xE9, 0x0038); wr_cmd(0xF1, 0x0001); wr_cmd(0xF2, 0x0010); wr_cmd(0x27, 0x00A3); //power voltage wr_cmd(0x1B, 0x001B); wr_cmd(0x1A, 0x0001); wr_cmd(0x24, 0x002F); wr_cmd(0x25, 0x0057); //VCOM offset wr_cmd(0x23, 0x008D); //for flicker adjust //power on wr_cmd(0x18, 0x0036); wr_cmd(0x19, 0x0001); //start osc wr_cmd(0x01, 0x0000); //wakeup wr_cmd(0x1F, 0x0088); _delay_ms(5); wr_cmd(0x1F, 0x0080); _delay_ms(5); wr_cmd(0x1F, 0x0090); _delay_ms(5); wr_cmd(0x1F, 0x00D0); _delay_ms(5); //color selection wr_cmd(0x17, 0x0005); //0x0005=65k, 0x0006=262k //panel characteristic wr_cmd(0x36, 0x0000); //display on wr_cmd(0x28, 0x0038); _delay_ms(40); wr_cmd(0x28, 0x003C); //display options display_set_orientation(0); }
void MI0283QT2::drawStart(void) { CS_ENABLE(); wr_spi(LCD_REGISTER); wr_spi(0x22); CS_DISABLE(); CS_ENABLE(); wr_spi(LCD_DATA); return; }
void S65L2F50::begin(uint_least8_t clock_div) { //init pins #if defined(RST_PIN) pinMode(RST_PIN, OUTPUT); RST_ENABLE(); #endif pinMode(CS_PIN, OUTPUT); pinMode(RS_PIN, OUTPUT); pinMode(SCK_PIN, OUTPUT); pinMode(MOSI_PIN, OUTPUT); CS_DISABLE(); #if !defined(SOFTWARE_SPI) SPI.setDataMode(SPI_MODE0); SPI.setBitOrder(MSBFIRST); //SPI.setClockDivider(clock_div); SPI.begin(); #endif //SPI speed-down #if !defined(SOFTWARE_SPI) # if F_CPU >= 128000000UL SPI.setClockDivider(SPI_CLOCK_DIV64); # elif F_CPU >= 64000000UL SPI.setClockDivider(SPI_CLOCK_DIV32); # elif F_CPU >= 32000000UL SPI.setClockDivider(SPI_CLOCK_DIV16); # elif F_CPU >= 16000000UL SPI.setClockDivider(SPI_CLOCK_DIV8); # else //elif F_CPU >= 8000000UL SPI.setClockDivider(SPI_CLOCK_DIV4); # endif #endif //reset display reset(); //SPI speed-up #if !defined(SOFTWARE_SPI) SPI.setClockDivider(clock_div); #endif return; }
unsigned char SD_command(unsigned char cmd, unsigned long arg, unsigned char crc, unsigned char read) { unsigned char i, buffer[8], ret = 0xFF; #ifdef DEBUG USART_printstr(" CMD "); USART_printhex(cmd); #endif CS_ENABLE(); SPI_transfer(cmd); SPI_transfer(arg >> 24); SPI_transfer(arg >> 16); SPI_transfer(arg >> 8); SPI_transfer(arg); SPI_transfer(crc); for (i = 0; i < read; i++) buffer[i] = SPI_transfer(0xFF); CS_DISABLE(); for (i = 0; i < read; i++) { #ifdef DEBUG USART_printch(' '); USART_printhex(buffer[i]); #endif if (buffer[i] != 0xFF) ret = buffer[i]; } #ifdef DEBUG USART_printstr("\r\n"); #endif return ret; }
void ADS7846_begin(void) { ti_lib_ioc_pin_type_gpio_output(BOARD_IOID_TOUCH_CS); ti_lib_ioc_pin_type_gpio_output(BOARD_IOID_SPI_MOSI); ti_lib_ioc_pin_type_gpio_output(BOARD_IOID_SPI_SCK); ti_lib_ioc_pin_type_gpio_input(BOARD_IOID_SPI_MISO); CS_DISABLE(); #ifdef IRQ_PIN pinMode(IRQ_PIN, INPUT); digitalWrite(IRQ_PIN, HIGH); //pull-up #endif #ifdef BUSY_PIN pinMode(BUSY_PIN, INPUT); digitalWrite(BUSY_PIN, HIGH); //pull-up #endif #if !defined(SOFTWARE_SPI) SPI.setDataMode(SPI_MODE0); SPI.begin(); #endif //set vars tp_matrix.div = 0; tp_x = 0; tp_y = 0; tp_last_x = 0; tp_last_y = 0; lcd_x = 0; lcd_y = 0; pressure = 0; ADS7846_setOrientation(0); return; }
void ADS7846::rd_data(void) { uint_least8_t p, a1, a2, b1, b2; uint_least16_t x, y; //SPI speed-down #if !defined(SOFTWARE_SPI) && defined(__AVR__) uint_least8_t spcr, spsr; spcr = SPCR; spsr = SPSR; # if F_CPU >= 8000000UL SPI.setClockDivider(SPI_CLOCK_DIV4); # else if F_CPU >= 4000000UL SPI.setClockDivider(SPI_CLOCK_DIV2); # endif #endif //get pressure CS_ENABLE(); wr_spi(CMD_START | CMD_8BIT | CMD_DIFF | CMD_Z1_POS); a1 = rd_spi()&0x7F; wr_spi(CMD_START | CMD_8BIT | CMD_DIFF | CMD_Z2_POS); b1 = (255-rd_spi())&0x7F; CS_DISABLE(); p = a1 + b1; if(p > MIN_PRESSURE) { /*//using 4 samples for x and y position for(x=0, y=0, i=4; i!=0; i--) { CS_ENABLE(); //get X data wr_spi(CMD_START | CMD_12BIT | CMD_DIFF | CMD_X_POS); a = rd_spi(); b = rd_spi(); x += 1023-((a<<2)|(b>>6)); //12bit: ((a<<4)|(b>>4)) //10bit: ((a<<2)|(b>>6)) //get Y data wr_spi(CMD_START | CMD_12BIT | CMD_DIFF | CMD_Y_POS); a = rd_spi(); b = rd_spi(); y += ((a<<2)|(b>>6)); //12bit: ((a<<4)|(b>>4)) //10bit: ((a<<2)|(b>>6)) CS_DISABLE(); } x >>= 2; //x/4 y >>= 2; //y/4*/ //using 2 samples for x and y position CS_ENABLE(); //get X data wr_spi(CMD_START | CMD_12BIT | CMD_DIFF | CMD_X_POS); a1 = rd_spi(); b1 = rd_spi(); wr_spi(CMD_START | CMD_12BIT | CMD_DIFF | CMD_X_POS); a2 = rd_spi(); b2 = rd_spi(); if(a1 == a2) { x = 1023-((a2<<2)|(b2>>6)); //12bit: ((a<<4)|(b>>4)) //10bit: ((a<<2)|(b>>6)) //get Y data wr_spi(CMD_START | CMD_12BIT | CMD_DIFF | CMD_Y_POS); a1 = rd_spi(); b1 = rd_spi(); wr_spi(CMD_START | CMD_12BIT | CMD_DIFF | CMD_Y_POS); a2 = rd_spi(); b2 = rd_spi(); if(a1 == a2) { y = ((a2<<2)|(b2>>6)); //12bit: ((a<<4)|(b>>4)) //10bit: ((a<<2)|(b>>6)) if(x && y) { tp_x = x; tp_y = y; } pressure = p; }
uint8_t REDFLY::init(uint32_t br, uint8_t pwr) { uint8_t ret=0xFF, i; uint32_t ms; //init pins #ifdef CS_PIN pinMode(CS_PIN, OUTPUT); CS_DISABLE(); //deselect #endif #ifdef RST_PIN pinMode(RST_PIN, OUTPUT); RST_ENABLE(); //reset on #endif #ifdef TX_PIN pinMode(TX_PIN, OUTPUT); digitalWrite(TX_PIN, HIGH); #endif #ifdef RX_PIN pinMode(RX_PIN, INPUT); digitalWrite(RX_PIN, HIGH); //pull-up on #endif //reset vars memset(ipaddr, 0, sizeof(ipaddr)); memset(buffer, 0, sizeof(buffer)); //set serial port config baudrate = br; setbaudrate(br); //enable module communication enable(); //reset module RST_ENABLE(); delay_10ms(5); //wait 50ms RST_DISABLE(); //auto baud rate detection delay_10ms(11); //wait 110ms for module boot-up for(i=4; i!=0; i--) //try 4 times { write(0x1C); //transmit 0x1C for(ms=millis(); (millis()-ms) < 200;) //wait 200ms for response { if(available()) { if(read() == 0x55) //wait for 0x55 { write(0x55); //transmit 0x55 delay_10ms(10); //wait 100ms //skip firmware upgrade question at power on write('n'); write('\n'); ret = 0xFE; i = 1; //break 1st for loop break; //break 2nd for loop } } } } delay_10ms(20); //wait 200ms for booting //get firmware version and set config // if(ret == 0xFE) // { for(i=3; i!=0; i--) //try 3 times { flush(); if(cmd(PSTR(CMD_FWVERSION)) == 0) { //cmd(PSTR(CMD_RESET)); //soft reset cmd(PSTR(CMD_BAND BAND24)); cmd(PSTR(CMD_INIT)); tx_power = pwr; ret = 0; break; } delay_10ms(10); } // } if(ret) { disable(); } return ret; }
void MI0283QT9::drawStop(void) { CS_DISABLE(); return; }