/* cause a ship to be constrained in a box (x,y)-(x,y) */ void p_x_y_box(struct player *pl, int p_x_min, int p_y_min, int p_x_max, int p_y_max) { pl->p_x_min = spi(p_x_min); pl->p_x_max = spi(p_x_max); pl->p_y_min = spi(p_y_min); pl->p_y_max = spi(p_y_max); }
/* reset constraint to whole galactic */ void p_x_y_unbox(struct player *pl) { pl->p_x_min = spi(0); pl->p_x_max = spi(GWIDTH); pl->p_y_min = spi(0); pl->p_y_max = spi(GWIDTH); }
int sdmmc_read_block(uint32_t address, uint8_t *buffer) { int i; int result; // CMD17 - READ_SINGLE_BLOCK result = sdmmc_cmd(17, block_addressing ? address : address << 9); if (result < 0) { cs_high(); return -1; } // wait for data token for (i = 0; i < TOKEN_COUNT; i++) { if (spi(0xff) == 0xfe) { break; } } if (i == TOKEN_COUNT) { return -2; } // read data for (i = 0; i < 512; i++) { *buffer++ = spi(0xff); } // skip CRC spi(0xff); spi(0xff); sdmmc_cmd_term(); return 0; }
void print_string(char * message){ // Write message to LCD (C string type) spi(CMD,0xae); // disable display; while (*message){ // Look for end of string print_char(*message++); } spi(CMD,0xaf); // enable display; }
void t_x_y_set(struct torp *k, int t_x, int t_y) { k->t_x = t_x; k->t_y = t_y; k->t_x_internal = spi(t_x); k->t_y_internal = spi(t_y); }
/* request new coordinates in unsynchronised fashion */ void p_x_y_set(struct player *j, int p_x, int p_y) { j->p_x_input = spi(p_x); j->p_y_input = spi(p_y); j->p_x_y_set++; /* note: request not obeyed until ship is !(PFDOCK|PFORBIT) */ }
/* set coordinates for a new ship, caller should be synchronised to daemon */ void p_x_y_go(struct player *pl, int p_x, int p_y) { pl->p_x = p_x; pl->p_y = p_y; pl->p_x_internal = spi(p_x); pl->p_y_internal = spi(p_y); pl->p_x_y_set = 0; }
static void ICACHE_FLASH_ATTR showNextInvertedChar(const char *c, uint8 w) { uint8 pxCol; const uint8 *p = &ASCII[(uint8)(*c - ' ')][0]; for (pxCol=0; pxCol<w; pxCol++) { spi(~*(p++)); } spi(0); }
//============================================================================== void ICACHE_FLASH_ATTR LINES() { int i; Gotoxy(0,2); for(i = 0; i < 96; i++) spi(_DATA, 0x18); Gotoxy(0,6); for(i = 0; i < 96; i++) spi(_DATA, 0x18); }
void ICACHE_FLASH_ATTR clearLcd() { int res; easygpio_outputSet(LCD_SCE, 0); spi(0x40); // Y=0 spi(0x80); // X=0 easygpio_outputSet(LCD_D_C, 1); for(res=0; res<504; res++) { spi(0x00); } easygpio_outputSet(LCD_SCE, 1); }
//----------------------------------------------- void DF_memo_to_256(void) { //GPIOD->ODR&=~(1<<2); CS_ON spi(0x3d); spi(0x2a); spi(0x80); spi(0xa6); //GPIOD->ODR|=(1<<2); CS_OFF }
//----------------------------------------------- char DF_status_read(void) { char d0; //GPIOD->ODR&=~(1<<2); CS_ON spi(0xd7); d0=spi(0xff); //GPIOD->ODR|=(1<<2); CS_OFF return d0; }
//----------------------------------------------- char ST_status_read(void) { char d0; //GPIOD->ODR&=~(1<<2); ST_CS_ON spi(0x05); d0=spi(0xff); //GPIOD->ODR|=(1<<2); ST_CS_OFF return d0; }
void ICACHE_FLASH_ATTR showChar(const char *c, uint8 charCol, uint8 charRow) { const uint8 w = 5; uint8 pxCol; easygpio_outputSet(LCD_SCE, 0); easygpio_outputSet(LCD_D_C, 1); gotoXY(charCol*(w+1), charRow); for (pxCol=0; pxCol<w; pxCol++) { spi(ASCII[(int)(*c - ' ')][pxCol]); } spi(0); easygpio_outputSet(LCD_SCE, 1); }
int initRAM(volatile uint8_t *port, int bit){ ram_cs_port = port; ram_cs_bit = bit; byte mode; cselect(1); spi(0x05); // read mode register mode = spi(0); // First 3 bytes are junk cselect(0); return mode == 0x40; // default mode, sequential read / write }
//============================================================================== void ICACHE_FLASH_ATTR Lcd_Init(void){ //P3DIR |= (BIT0 | BIT1 | BIT2 | BIT3); easygpio_pinMode(pinSclk, EASYGPIO_NOPULL, EASYGPIO_OUTPUT); easygpio_pinMode(pinSdin, EASYGPIO_NOPULL, EASYGPIO_OUTPUT); easygpio_pinMode(pinSce, EASYGPIO_NOPULL, EASYGPIO_OUTPUT); easygpio_pinMode(pinReset, EASYGPIO_NOPULL, EASYGPIO_OUTPUT); cs(0);// = 0; rst(0);// = 0; os_delay_us(10000); // 5mS so says the stop watch(less than 5ms will not work) rst(1);// = 1; // STE2007 controller initialization spi(CMD, 0x2F);//Включение дисплея spi(CMD, 0x38);//Включение термокомпенсации spi(CMD, 0xA0);//Инверсия отображения spi(CMD, 0xA6);//0xA7 - инверсия отображения spi(CMD, 0x9f);//Установка контраста spi(CMD, 0xEC);//Установка частоты обновления 80 Гц //spi(CMD,0xC8); // mirror Y axis (about X axis) //spi(CMD,0xA1); spi(CMD, 0xAF);//Разрешение работы LCD spi(CMD, 0xA4);//Очистка экрана Lcd_Clear(); // clear LCD //LINES(); }
//----------------------------------------------- void DF_buffer_to_page(/*char buff,*/unsigned page_addr) { char d0; d0=0x88; //page_addr<<=1; //GPIOD->ODR&=~(1<<2); CS_ON spi(d0); spi(page_addr/256/**(((char*)&page_addr)+1)*/); spi(page_addr%256/**((char*)&page_addr)*/); spi(0xff); //GPIOD->ODR|=(1<<2); CS_OFF }
int readRAM(uint32_t start, unsigned char *buf, uint32_t len){ cselect(1); spi(0x03); // read // Send address, high byte first spi(start >> 16); spi(start >> 8); spi(start); for(int n=0; n<len; n++){ buf[n] = spi(0); }; cselect(0); return len; }
static void send_file_to_fpga(std::string &file_name, gpio &error, gpio &done) { std::ifstream bitstream; std::cout << "File name - " << file_name.c_str() << std::endl; bitstream.open(file_name.c_str(), std::ios::binary); if (!bitstream.is_open()) std::cout << "File " << file_name << " not opened succesfully." << std::endl; spidev spi("/dev/spidev1.0"); char buf[BUF_SIZE]; char rbuf[BUF_SIZE]; do { bitstream.read(buf, BUF_SIZE); spi.send(buf, rbuf, bitstream.gcount()); if (error.get_value()) std::cout << "INIT_B went high, error occured." << std::endl; if (!done.get_value()) std::cout << "Configuration complete." << std::endl; } while (bitstream.gcount() == BUF_SIZE); }
static void send_file_to_fpga(const std::string &file_name, gpio &error, gpio &done) { std::ifstream bitstream; bitstream.open(file_name.c_str(), std::ios::binary); if (!bitstream.is_open()) throw uhd::os_error( "Could not open the file: " + file_name ); spidev spi("/dev/spidev1.0"); char buf[BUF_SIZE]; char rbuf[BUF_SIZE]; do { bitstream.read(buf, BUF_SIZE); spi.send(buf, rbuf, bitstream.gcount()); if (error.get_value()) throw uhd::os_error("INIT_B went high, error occured."); if (!done.get_value()) UHD_MSG(status) << "Configuration complete." << std::endl; } while (bitstream.gcount() == BUF_SIZE); }
void Nhdc12832::cmd_out(unsigned char c){ Spi spi(spi_port); assert_cmd(); assert_cs(); spi.swap(c); deassert_cs(); }
void Nhdc12832::refresh(void){ Spi spi(spi_port); uint8_t buffer[MEM_ROWS]; unsigned int i,j; unsigned char page = 0xB0; //Page Address + 0xB0 //cmd_out(0xAE); //Display OFF cmd_out(0x40); //Display start address + 0x40 for(i=0;i<MEM_COLUMNS;i++){ //32pixel display / 8 pixels per page = 4 pages assert_cmd(); buffer[0] = page; //send page address buffer[1] = 0x10; //column address upper 4 bits + 0x10 buffer[2] = 0x00; //column address lower 4 bits + 0x00 assert_cs(); spi.write(buffer, 3); deassert_cs(); for(j=0;j<MEM_ROWS;j++){ //128 rows wide buffer[j] = nhd_mem[j][i]; } assert_data(); assert_cs(); spi.write(buffer, MEM_ROWS); deassert_cs(); page++; //after 128 columns, go to next page } cmd_out(0xAF); //Display ON }
int writeRAM(uint32_t start, unsigned char *buf, uint32_t len){ cselect(1); spi(0x02); // write // Send address, high byte first spi(start >> 16); spi(start >> 8); spi(start); for(int n=0; n<len; n++){ spi(buf[n]); }; cselect(0); return len; }
//============================================================================== void ICACHE_FLASH_ATTR _print_char(char c) { int i = 0; for (i = 0; i < 6; i++ ) { spi(_DATA, ~Font8x6[c*6+i]); } }
//----------------------------------------------- void ST_WREN(void) { //GPIOD->ODR&=~(1<<2); ST_CS_ON spi(0x06); //GPIOD->ODR|=(1<<2); ST_CS_OFF }
int sdmmc_write_multiple_blocks(uint32_t address, uint32_t n_blocks, uint8_t (*next_byte)()) { int result; int i; if ((result = sdmmc_cmd(25, block_addressing ? address : address << 9)) < 0) { cs_high(); return result; } spi(0xff); // initiate write while (n_blocks--) { spi(0xfc); // data token for (i = 0; i < 512; i++) { // sector data spi(next_byte()); } spi(0xff); // CRC spi(0xff); result = spi(0xff); // data response if ((result & 0x1f) != 0x05) { cs_high(); return result; } i = 0; do { // wait while card is busy if (++i == 131072) { cs_high(); return -10; } } while (spi(0xff) != 0xff); } return sdmmc_stop_transmission(); }
//============================================================================== void char_10x16(unsigned int aX, unsigned int aY, unsigned int aDig) { int i = 0, j = 0; for(i = 0; i < 2; i++) { Gotoxy(aX,aY+i); for(j = 0; j < 10; j++) spi(_DATA, courier_10x16[j+i*10 + aDig*10*2]); } }
int main(int argc, char* argv[]) { int ret = 0; // 产生一个 CUstpFtdcTraderApi 实例 CUstpFtdcTraderApi *pTrader = CUstpFtdcTraderApi::CreateFtdcTraderApi(""); g_puserapi=pTrader; CTraderSpi spi(pTrader); spi.Init(); /** 注册一事件处理的实例 */ pTrader->RegisterSpi(&spi); /** 设置飞马平台服务的地址 */ // 可以注册多个地址备用 spi.logging("register front addr: %s", spi.GetFrontAddr()); pTrader->RegisterFront(spi.GetFrontAddr()); /** 订阅私有流 */ // USTP_TERT_RESTART:从本交易日开始重传 // USTP_TERT_RESUME:从上次收到的续传 // USTP_TERT_QUICK:只传送登录后私有流的内容 pTrader->SubscribePrivateTopic(USTP_TERT_QUICK); /** 订阅公共流 */ // USTP_TERT_RESTART:从本交易日开始重传 // USTP_TERT_RESUME:从上次收到的续传 // USTP_TERT_QUICK:只传送登录后公共流的内容 pTrader->SubscribePublicTopic(USTP_TERT_QUICK); /** 使客户端开始与后台服务建立连接 */ spi.logging("Init trader\n"); const fmconf_t* cfg = spi.GetConf(); lmice_warning_print("UserID=[%s],BrokerID=[%s],Password=[%s]\n", cfg->g_UserID,cfg->g_BrokerID,cfg->g_Password); pTrader->Init(); /** Listen and wait to end */ signal(SIGINT, signal_handler); /*signal(SIGCHLD,SIG_IGN); ignore child */ /* signal(SIGTSTP,SIG_IGN); ignore tty signals */ signal(SIGTERM,signal_handler); /* catch kill signal */ while(1) { if(g_quit_flag == 1) { break; } usleep(500000); } pTrader->Release(); lmice_warning_print("Release\n"); return 0; }
//============================================================================== void char_24x16(unsigned int aDig, unsigned int aX, unsigned int aY) { int i = 0, j = 0; for(i = 0; i < SYM_HEIGHT; i++) { Gotoxy(aX,aY+i); for(j = 0; j < SYM_WIDGHT; j++) spi(_DATA, Times_16x24[j+i*SYM_WIDGHT + aDig*SYM_WIDGHT*SYM_HEIGHT]); } }
//----------------------------------------------- long DF_mf_dev_read(void) { char d0,d1,d2,d3; d0=0; d1=0; d2=0; d3=0; //GPIOD->ODR&=~(1<<2); CS_ON spi(0x9f); mdr0=spi(0xff); mdr1=spi(0xff); mdr2=spi(0xff); mdr3=spi(0xff); //GPIOD->ODR|=(1<<2); CS_OFF return *((long*)&d0); }