void sst25vf_share_write_status(const device_cfg_t * cfg, uint8_t status){ sst25vf_share_write_enable(cfg); sst25vf_share_assert_cs(cfg); hwpl_spi_swap(cfg->periph.port, (void*)(ssize_t)SST25VF_INS_WR_STATUS); hwpl_spi_swap(cfg->periph.port, (void*)(ssize_t)status); sst25vf_share_deassert_cs(cfg); }
uint8_t sst25vf_share_read_status(const device_cfg_t * cfg){ uint8_t status; sst25vf_share_assert_cs(cfg); hwpl_spi_swap(cfg->periph.port, (void*)SST25VF_INS_RD_STATUS); status = hwpl_spi_swap(cfg->periph.port, (void*)(ssize_t)0xFF); sst25vf_share_deassert_cs(cfg); return status; }
char sst25vf_share_read_byte(const device_cfg_t * cfg, uint32_t addr){ char byte; sst25vf_share_assert_cs(cfg); sst25vf_share_write_opcode_addr(cfg, SST25VF_INS_RD_HS, addr); hwpl_spi_swap(cfg->periph.port, 0); //dummy byte output byte = hwpl_spi_swap(cfg->periph.port, (void*)(ssize_t)0xFF); sst25vf_share_deassert_cs(cfg); return byte; }
void sst25vf_share_read_id(const device_cfg_t * cfg, char * dest){ int i; sst25vf_share_assert_cs(cfg); hwpl_spi_swap(cfg->periph.port, (void*)(ssize_t)SST25VF_INS_RD_ID); for(i=0; i < 4; i++){ dest[i] = hwpl_spi_swap(cfg->periph.port, (void*)(ssize_t)0xFF); } sst25vf_share_deassert_cs(cfg); }
void sst25vf_share_write_opcode_addr(const device_cfg_t * cfg, uint8_t opcode, uint32_t addr){ uint8_t * addrp; addrp = (uint8_t*)&addr; //send the opcode hwpl_spi_swap(cfg->periph.port, (void*)(ssize_t)opcode); //send the 3-byte address MSB to LSB (assumes little-endian arch) hwpl_spi_swap(cfg->periph.port, (void*)(ssize_t)addrp[2]); hwpl_spi_swap(cfg->periph.port, (void*)(ssize_t)addrp[1]); hwpl_spi_swap(cfg->periph.port, (void*)(ssize_t)addrp[0]); }
void sst25vf_share_write_byte(const device_cfg_t * cfg, uint32_t addr, char byte){ sst25vf_share_write_enable(cfg); sst25vf_share_assert_cs(cfg); sst25vf_share_write_opcode_addr(cfg, SST25VF_INS_PROGRAM, addr); hwpl_spi_swap(cfg->periph.port, (void*)(ssize_t)byte); sst25vf_share_deassert_cs(cfg); }
void sst25vf_share_write_quick_opcode(const device_cfg_t * cfg, uint8_t opcode){ sst25vf_share_assert_cs(cfg); hwpl_spi_swap(cfg->periph.port, (void*)(ssize_t)opcode); sst25vf_share_deassert_cs(cfg); }
int lcd_ioctl(const device_cfg_t * cfg, int request, void * ctl){ mlcd_attr_t * attr = (mlcd_attr_t*)ctl; tmr_action_t action; pio_attr_t pattr; device_periph_t p; switch(request){ case I_MLCD_GETATTR: attr->freq = LCD_FREQ; //LCD updates 30 times per second attr->h = LCD_HEIGHT; attr->w = LCD_WIDTH; attr->size = LCD_ROWS * LCD_COLS; attr->mem = mem; attr->hold = lcd_hold; attr->rows = LCD_ROWS; attr->cols = LCD_COLS/4; attr->orientation = (ORIENT_BOTTOM)|(ORIENT_LEFT); break; case I_MLCD_CLEAR: memset(mem, 0, LCD_ROWS * LCD_COLS); lcd_hold = 0x80; break; case I_MLCD_HOLD: if( LCD_HOLD_COUNT() < 127 ){ lcd_hold++; } break; case I_MLCD_RELEASE: if( LCD_HOLD_COUNT() > 0 ){ lcd_hold--; LCD_TOUCH(); } break; case I_MLCD_INIT: //initialize the IO -- chip select first pattr.mask = LCD_SPI_CS_PINMASK; pattr.mode = PIO_MODE_OUTPUT; p.port = LCD_SPI_CS_PORT; hwpl_pio_open((device_cfg_t*)&p); hwpl_pio_setattr(LCD_SPI_CS_PORT, &pattr); hwpl_pio_setmask(LCD_SPI_CS_PORT, (void*)LCD_SPI_CS_PINMASK); //Now A0 pattr.mask = LCD_SPI_A0_PINMASK; if( p.port != LCD_SPI_A0_PORT ){ p.port = LCD_SPI_A0_PORT; hwpl_pio_open((device_cfg_t*)&p); } hwpl_pio_setattr(LCD_SPI_A0_PORT, &pattr); hwpl_pio_setmask(LCD_SPI_A0_PORT, (void*)LCD_SPI_A0_PINMASK); //configure the timer to update the LCD action.channel = LCD_USECOND_OC; action.event = TMR_ACTION_EVENT_INTERRUPT; action.callback = lcd_usecond_match_event; action.context = (void*)cfg; hwpl_tmr_setaction(LCD_USECOND_TMR, &action); const char start[] = {0xA0, 0xAE, 0xC0, 0xA2, 0x2F, 0x21, 0x81, 0x2F}; int i; const char * p = (const char*)start; command_mode(); hwpl_pio_clrmask(LCD_SPI_A0_PORT, (void*)LCD_SPI_A0_PINMASK); //enter command mode for(i=0; i < 8; i++){ assert_cs(); hwpl_spi_swap(LCD_SPI_PORT, (void*)(uint32_t)(*p++)); deassert_cs(); } //start the timer update to refresh the screen update_count(); break; case I_MLCD_ON: command_mode(); assert_cs(); hwpl_spi_swap(LCD_SPI_PORT, (void*)0xAF); deassert_cs(); break; case I_MLCD_OFF: command_mode(); assert_cs(); hwpl_spi_swap(LCD_SPI_PORT, (void*)0xAE); deassert_cs(); break; default: errno = EINVAL; return -1; } return 0; }