/* FLASH (special var header: size, id, flag, offset, page) */ int ti73_send_REQ2_h(CalcHandle* handle, uint16_t appsize, uint8_t apptype, const char *appname, uint8_t appattr) { uint8_t buffer[16] = { 0 }; buffer[0] = LSB(appsize); buffer[1] = MSB(appsize); buffer[2] = apptype; memcpy(buffer + 3, appname, 8); pad_buffer(buffer + 3, '\0'); ticalcs_info(" PC->TI: REQ (size=0x%04X, id=%02X, name=%s)", appsize, apptype, appname); TRYF(dbus_send(handle, PC_TI7383, CMD_REQ, 11, buffer)); return 0; }
void HID_Set_Idle() { printf("Set Idle\n"); UCHAR duration = MSB(ControlData.DeviceRequest.wValue); UCHAR reportID = LSB(ControlData.DeviceRequest.wValue); printf("Duration: %x, ReportID: %x\n", duration, reportID); hid_settings.idle_time = 0; if(duration != 0) { hid_settings.idle_time = duration * 4; //wait time in milliseconds } if(reportID != 0) { printf("ReportID = %ud\n", reportID); } hid_settings.state = connected; }
/** Loads the specified key into the ZNP. Does not change security mode, need to use setSecurityMode() too. @note if NOT using pre-configured keys then the coordinator will distribute its key to all devices. @param key preConfiguredKey a 16B key to use @pre setSecurityMode() called @post znpResult contains the error code, or ZNP_SUCCESS if success. */ void setSecurityKey(unsigned char* key) { #ifdef ZNP_INTERFACE_VERBOSE printf("Setting Security Key: "); printHexBytes(key, ZCD_NV_PRECFGKEY_LEN); #endif znpBuf[0] = ZB_WRITE_CONFIGURATION_LEN + ZCD_NV_PRECFGKEY_LEN; znpBuf[1] = MSB(ZB_WRITE_CONFIGURATION); znpBuf[2] = LSB(ZB_WRITE_CONFIGURATION); znpBuf[3] = ZCD_NV_PRECFGKEY; znpBuf[4] = ZCD_NV_PRECFGKEY_LEN; for (int i=5; i<(ZCD_NV_PRECFGKEY_LEN+5); i++) znpBuf[i] = key[i]; znpResult = sendMessage(); }
void main(void) { static unsigned char i,row; static int y; static unsigned int adr; pal_col(1,0x30);//set while color y=0; update_list[0]=0x20|NT_UPD_HORZ;//horizontal update sequence, dummy address update_list[1]=0x00; update_list[2]=32;//update sequence is 32 tiles wide update_list[3+32]=NT_UPD_EOF; set_vram_update(update_list); ppu_on_all();//enable rendering while(1) { scroll(0,y);//scroll value will be applied on the next nmi if(!(y&7))//put new row every 8 pixels { row=(y>>3)+59;//get row number for update, it is shifted just above the visible part of the screen if(row>=60) row-=60;//keep the row number within the limits adr=row<<5;//convert Y from pixels to tiles (row=y/8), then to nametable offset (offset=row*32) if(adr<960) adr=adr|NAMETABLE_A; else adr=(adr-960)|NAMETABLE_C;//add base address of one of two nametables update_list[0]=MSB(adr)|NT_UPD_HORZ;//set the address update_list[1]=LSB(adr); for(i=0;i<32;++i) update_list[3+i]=0x10+(rand8()&7);//fill row buffer with random tiles } --y;//next pixel if(y<0) y=240*2-1;//keep Y within the total height of two nametables ppu_wait_nmi(); }
// 0xEE00: error TIEXPORT3 int TICALL dusb_cmd_s_error(CalcHandle *handle, uint16_t code) { DUSBVirtualPacket* pkt; int retval = 0; VALIDATE_HANDLE(handle); pkt = dusb_vtl_pkt_new_ex(handle, 2, DUSB_VPKT_ERROR, dusb_vtl_pkt_alloc_data(2)); pkt->data[0] = MSB(code); pkt->data[1] = LSB(code); retval = dusb_send_data(handle, pkt); dusb_vtl_pkt_del(handle, pkt); ticalcs_info(" code = %04x", code); return retval; }
void EEPROMRead(WORD addr, BYTE length, BYTE xdata *buf) { BYTE i = 0; BYTE j = 0; BYTE xdata ee_str[2]; if(DB_Addr) ee_str[i++] = MSB(addr); ee_str[i++] = LSB(addr); EZUSB_WriteI2C(I2C_Addr, i, ee_str); for(j=0; j < length; j++) *(buf+j) = 0xcd; EZUSB_ReadI2C(I2C_Addr, length, buf); }
void dm9000WritePhyReg(uint8_t address, uint16_t data) { //Write PHY register address dm9000WriteReg(DM9000_REG_EPAR, 0x40 | address); //Write register value dm9000WriteReg(DM9000_REG_EPDRL, LSB(data)); dm9000WriteReg(DM9000_REG_EPDRH, MSB(data)); //Start the write operation dm9000WriteReg(DM9000_REG_EPCR, EPCR_EPOS | EPCR_ERPRW); //PHY access is still in progress? while(dm9000ReadReg(DM9000_REG_EPCR) & EPCR_ERRE); //Wait 5us minimum usleep(5); //Clear command register dm9000WriteReg(DM9000_REG_EPCR, EPCR_EPOS); }
/* Request to send (std var header: NUL padded, fixed length) */ TIEXPORT3 int TICALL ti73_send_RTS(CalcHandle* handle, uint16_t varsize, uint8_t vartype, const char *varname, uint8_t varattr) { uint8_t buffer[16]; char trans[9]; if (handle == NULL) { ticalcs_critical("%s: handle is NULL", __FUNCTION__); return ERR_INVALID_HANDLE; } if (varname == NULL) { ticalcs_critical("%s: varname is NULL", __FUNCTION__); return ERR_INVALID_PACKET; } buffer[0] = LSB(varsize); buffer[1] = MSB(varsize); buffer[2] = vartype; memcpy(buffer + 3, varname, 8); buffer[11] = 0x00; buffer[12] = (varattr == ATTRB_ARCHIVED) ? 0x80 : 0x00; /* Kludge to support 84+CSE Pic files. Please do not rely on this behavior; it will go away in the future. */ if (vartype == 0x07 && varsize == 0x55bb) buffer[11] = 0x0a; ticonv_varname_to_utf8_s(handle->model, varname, trans, vartype); ticalcs_info(" PC->TI: RTS (size=0x%04X, id=%02X, name=%s, attr=%i)", varsize, vartype, trans, varattr); if (vartype != TI7383_BKUP) { // backup: special header pad_buffer_to_8_chars(buffer + 3, '\0'); TRYF(dbus_send(handle, PC_TI7383, CMD_RTS, 11 + EXTRAS, buffer)); } else { TRYF(dbus_send(handle, PC_TI7383, CMD_RTS, 9, buffer)); } return 0; }
BOOL eeprom_read (BYTE prom_addr, WORD addr, WORD length, BYTE *buf) { BYTE eeprom_addr[2]; BYTE addr_len=0; if (EEPROM_TWO_BYTE) eeprom_addr[addr_len++] = MSB(addr); eeprom_addr[addr_len++] = LSB(addr); // write the address we want to read to the prom //printf ("Starting Addr Write with addr len %d\n", addr_len); if ( !i2c_write( prom_addr, addr_len, eeprom_addr, 0, NULL, 1) ) return FALSE; //printf ( "Starting read\n" ); if ( !i2c_read ( prom_addr, length, buf ) ) return FALSE; return TRUE; }
/* Request variable (std var header: NUL padded, fixed length) */ int ti82_send_REQ_h(CalcHandle* handle, uint16_t varsize, uint8_t vartype, const char *varname) { uint8_t buffer[16] = { 0 }; char trans[9]; buffer[0] = LSB(varsize); buffer[1] = MSB(varsize); buffer[2] = vartype; memcpy(buffer + 3, varname, 8); pad_buffer(buffer + 3, '\0'); ticonv_varname_to_utf8_s(handle->model, varname, trans, vartype); ticalcs_info(" PC->TI: REQ (size=0x%04X=%i, id=%02X, name=%s)", varsize, varsize, vartype, trans); TRYF(dbus_send(handle, PC_TI8283, CMD_REQ, 11, buffer)); return 0; }
/** Enable/Disabless callbacks on the ZNP. @param cb must be either CALLBACKS_ENABLED or CALLBACKS_DISABLED @see section ZCD_NV_ZDO_DIRECT_CB in ZNP Interface Specification @post znpResult contains the error code, or ZNP_SUCCESS if success. */ void setCallbacks(unsigned char cb) { if ((cb != CALLBACKS_ENABLED) && (cb != CALLBACKS_DISABLED)) { znpResult = -1; return; } #ifdef ZNP_INTERFACE_VERBOSE printf("Setting Callbacks to %s\r\n", (cb ? "ON" : "OFF")); #endif znpBuf[0] = ZB_WRITE_CONFIGURATION_LEN + ZCD_NV_ZDO_DIRECT_CB_LEN; znpBuf[1] = MSB(ZB_WRITE_CONFIGURATION); znpBuf[2] = LSB(ZB_WRITE_CONFIGURATION); znpBuf[3] = ZCD_NV_ZDO_DIRECT_CB; znpBuf[4] = ZCD_NV_ZDO_DIRECT_CB_LEN; znpBuf[5] = cb; znpResult = sendMessage(); }
/* FLASH (special var header: size, id, flag, offset, page) */ TIEXPORT3 int TICALL ti73_send_REQ2(CalcHandle* handle, uint16_t appsize, uint8_t apptype, const char *appname, uint8_t appattr) { uint8_t buffer[16] = { 0 }; if (appname == NULL) { ticalcs_critical("%s: appname is NULL", __FUNCTION__); return ERR_INVALID_PACKET; } buffer[0] = LSB(appsize); buffer[1] = MSB(appsize); buffer[2] = apptype; memcpy(buffer + 3, appname, 8); pad_buffer_to_8_chars(buffer + 3, '\0'); ticalcs_info(" PC->TI: REQ (size=0x%04X, id=%02X, name=%s)", appsize, apptype, appname); return dbus_send(handle, PC_TI7383, CMD_REQ, 11, buffer); }
/* Request variable (std var header: NUL padded, fixed length) */ TIEXPORT3 int TICALL ti73_send_REQ(CalcHandle* handle, uint16_t varsize, uint8_t vartype, const char *varname, uint8_t varattr) { uint8_t buffer[16] = { 0 }; char trans[17]; if (handle == NULL) { ticalcs_critical("%s: handle is NULL", __FUNCTION__); return ERR_INVALID_HANDLE; } if (varname == NULL) { ticalcs_critical("%s: varname is NULL", __FUNCTION__); return ERR_INVALID_PACKET; } buffer[0] = LSB(varsize); buffer[1] = MSB(varsize); buffer[2] = vartype; memcpy(buffer + 3, varname, 8); pad_buffer_to_8_chars(buffer + 3, '\0'); buffer[11] = 0x00; buffer[12] = (varattr == ATTRB_ARCHIVED) ? 0x80 : 0x00; ticonv_varname_to_utf8_s(handle->model, varname, trans, vartype); ticalcs_info(" PC->TI: REQ (size=0x%04X, id=%02X, name=%s, attr=%i)", varsize, vartype, trans, varattr); if (vartype != TI83p_IDLIST && vartype != TI83p_GETCERT) { TRYF(dbus_send(handle, PC_TI7383, CMD_REQ, 11 + EXTRAS, buffer)); } else if(vartype != TI83p_GETCERT && handle->model != CALC_TI73) { TRYF(dbus_send(handle, PC_TI7383, CMD_REQ, 11, buffer)); } else { TRYF(dbus_send(handle, PC_TI73, CMD_REQ, 3, buffer)); } return 0; }
int ti73_send_DEL_h(CalcHandle* handle, uint16_t varsize, uint8_t vartype, const char *varname, uint8_t varattr) { uint8_t buffer[16] = { 0 }; char trans[9]; buffer[0] = LSB(varsize); buffer[1] = MSB(varsize); buffer[2] = vartype == TI83p_APPL ? 0x14 : vartype; memcpy(buffer + 3, varname, 8); pad_buffer(buffer + 3, '\0'); buffer[11] = 0x00; ticonv_varname_to_utf8_s(handle->model, varname, trans, vartype); ticalcs_info(" PC->TI: DEL (name=%s)", trans); TRYF(dbus_send(handle, PC_TI7383, CMD_DEL, 11, buffer)); return 0; }
/* Request to send (var header: SPC padded, fixed length) */ int ti85_send_RTS(CalcHandle* handle, uint16_t varsize, uint8_t vartype, const char *varname) { uint8_t buffer[16]; char trans[9]; buffer[0] = LSB(varsize); buffer[1] = MSB(varsize); buffer[2] = vartype; buffer[3] = strlen(varname); memcpy(buffer + 4, varname, 8); pad_buffer_to_8_chars(buffer + 4, ' '); ticonv_varname_to_utf8_s(handle->model, varname, trans, vartype); ticalcs_info(" PC->TI: RTS (size=0x%04X, id=%02X, name=%s)", varsize, vartype, trans); TRYF(dbus_send(handle, PC_TI8586, CMD_RTS, 12, buffer)); return 0; }
void EEPROMWriteByte(WORD addr, BYTE value) { BYTE i = 0; BYTE xdata ee_str[3]; if(DB_Addr) ee_str[i++] = MSB(addr); // if 16 bit, we need 2-byte address and 1 byte data ee_str[i++] = LSB(addr); ee_str[i++] = value; //EZUSB_WriteI2C(I2C_Addr, i, ee_str); // http://www.keil.com/forum/docs/thread11160.asp while( I2CPckt.status != I2C_IDLE ); // wait for write session while(EZUSB_WriteI2C( I2C_Addr, i, ee_str )!=I2C_OK); EZUSB_WaitForEEPROMWrite( I2C_Addr ); // wait for Write Cycle Time // LED=1; }
/** Sets the Zigbee Device Type for the ZNP. @param deviceType the type of Zigbee device. Must be COORDINATOR, ROUTER, or END_DEVICE @post znpResult contains the error code, or ZNP_SUCCESS if success. */ void setZigbeeDeviceType(unsigned char deviceType) { if (deviceType > END_DEVICE) { znpResult = -1; return; } #ifdef ZNP_INTERFACE_VERBOSE printf("Setting Zigbee DeviceType to %s\r\n", getDeviceTypeName(deviceType)); #endif znpBuf[0] = ZB_WRITE_CONFIGURATION_LEN + ZCD_NV_LOGICAL_TYPE_LEN; znpBuf[1] = MSB(ZB_WRITE_CONFIGURATION); znpBuf[2] = LSB(ZB_WRITE_CONFIGURATION); znpBuf[3] = ZCD_NV_LOGICAL_TYPE; znpBuf[4] = ZCD_NV_LOGICAL_TYPE_LEN; znpBuf[5] = deviceType; znpResult = sendMessage(); }
void adc_sample_sent_cb(void) { uint32_t i; uint8_t old_mic_buf_id=mic_buf_id; if (!b_microphone_pause && Is_usb_write_enabled(EP_AUDIO_IN) && audio_mixer_dacs_input(NULL, 0) ) // Endpoint buffer free ? { mic_frame_id++; if( mic_frame_id>=10 ) { mic_frame_id=0; microphone[mic_buf_id].size = 45; } else microphone[mic_buf_id].size = 44; Usb_reset_endpoint_fifo_access(EP_AUDIO_IN); if(!mute) { for(i = 0; i < microphone[old_mic_buf_id].size; i++) { Usb_write_endpoint_data(EP_AUDIO_IN, 8, LSB(microphone[old_mic_buf_id].buffer[2 * i])); Usb_write_endpoint_data(EP_AUDIO_IN, 8, MSB(microphone[old_mic_buf_id].buffer[2 * i])); } } else { for(i = 0; i < 2*microphone[old_mic_buf_id].size; i++) { Usb_write_endpoint_data(EP_AUDIO_IN, 8, 0); } } Usb_ack_in_ready_send(EP_AUDIO_IN); audio_mixer_dacs_input(microphone[mic_buf_id].buffer, 45/*microphone[mic_buf_id].size*/); // Let's switch to the next buffer. mic_buf_id^=1; } else b_microphone_started=false; }
/**@brief Function for creating a TX message for writing a CCCD. * * @param[in] conn_handle Connection handle on which to perform the configuration. * @param[in] handle_cccd Handle of the CCCD. * @param[in] enable Enable or disable GATTC notifications. * * @retval NRF_SUCCESS If the message was created successfully. * @retval NRF_ERROR_INVALID_PARAM If one of the input parameters was invalid. */ static uint32_t cccd_configure(const uint16_t conn_handle, const uint16_t handle_cccd, bool enable) { tx_message_t * p_msg; uint16_t cccd_val = enable ? BLE_CCCD_NOTIFY_BIT_MASK : 0; p_msg = &m_tx_buffer[m_tx_insert_index++]; m_tx_insert_index &= TX_BUFFER_MASK; p_msg->req.write_req.gattc_params.handle = handle_cccd; p_msg->req.write_req.gattc_params.len = 2; p_msg->req.write_req.gattc_params.p_value = p_msg->req.write_req.gattc_value; p_msg->req.write_req.gattc_params.offset = 0; p_msg->req.write_req.gattc_params.write_op = BLE_GATT_OP_WRITE_REQ; p_msg->req.write_req.gattc_value[0] = LSB(cccd_val); p_msg->req.write_req.gattc_value[1] = MSB(cccd_val); p_msg->conn_handle = conn_handle; p_msg->type = WRITE_REQ; tx_buffer_process(); return NRF_SUCCESS; }
TIEXPORT3 int TICALL dusb_send_buf_size_request(CalcHandle* h, uint32_t size) { DUSBRawPacket raw; if (h == NULL) { ticalcs_critical("%s: h is NULL", __FUNCTION__); return ERR_INVALID_HANDLE; } memset(&raw, 0, sizeof(raw)); raw.size = 4; raw.type = DUSB_RPKT_BUF_SIZE_REQ; raw.data[2] = MSB(size); raw.data[3] = LSB(size); TRYF(dusb_send(h, &raw)); ticalcs_info(" PC->TI: Buffer Size Request (%i bytes)", size); return 0; }
/****************************************************************************** * Function: void USBStdGetStatusHandler(void) * * PreCondition: None * * Input: None * * Output: None * * Side Effects: None * * Overview: This routine handles the standard GET_STATUS request * * Note: None *****************************************************************************/ void USBStdGetStatusHandler(void) { CtrlTrfData._byte0 = 0; // Initialize content CtrlTrfData._byte1 = 0; switch(SetupPkt.Recipient) { case RCPT_DEV: ctrl_trf_session_owner = MUID_USB9; /* * _byte0: bit0: Self-Powered Status [0] Bus-Powered [1] Self-Powered * bit1: RemoteWakeup [0] Disabled [1] Enabled */ if(self_power == 1) // self_power defined in io_cfg.h CtrlTrfData._byte0|=0b000000001; // Set bit0 if(usb_stat.RemoteWakeup == 1) // usb_stat defined in usbmmap.c CtrlTrfData._byte0|=0b00000010; // Set bit1 break; case RCPT_INTF: ctrl_trf_session_owner = MUID_USB9; // No data to update break; case RCPT_EP: ctrl_trf_session_owner = MUID_USB9; /* * _byte0: bit0: Halt Status [0] Not Halted [1] Halted */ pDst.bRam = (byte*)&ep0Bo+(SetupPkt.EPNum*8)+(SetupPkt.EPDir*4); if(*pDst.bRam & _BSTALL) // Use _BSTALL as a bit mask CtrlTrfData._byte0=0x01;// Set bit0 break; }//end switch if(ctrl_trf_session_owner == MUID_USB9) { pSrc.bRam = (byte*)&CtrlTrfData; // Set Source usb_stat.ctrl_trf_mem = _RAM; // Set memory type LSB(wCount) = 2; // Set data count }//end if(...) }//end USBStdGetStatusHandler
void debugInit(uint32_t baudrate) { uint32_t pclk; //Power up UART0 LPC_SC->PCONP |= PCONP_PCUART0; //Configure P0.2 (TXD0) and P0.3 (RXD0) LPC_PINCON->PINSEL0 &= ~(PINSEL0_P0_2_MASK | PINSEL0_P0_3_MASK); LPC_PINCON->PINSEL0 |= PINSEL0_P0_2_TXD0 | PINSEL0_P0_3_RXD0; //Check the UART0 peripheral clock switch(LPC_SC->PCLKSEL0 & PCLKSEL0_PCLK_UART0) { case PCLKSEL0_PCLK_UART0_DIV1: pclk = SystemCoreClock; break; case PCLKSEL0_PCLK_UART0_DIV2: pclk = SystemCoreClock / 2; break; case PCLKSEL0_PCLK_UART0_DIV4: pclk = SystemCoreClock / 4; break; default: pclk = SystemCoreClock / 8; break; } //Configure UART0 (8 bits, no parity, 1 stop bit) LPC_UART0->LCR = LCR_DLAB | LCR_WORD_LENGTH_SELECT_8; //Set baudrate LPC_UART0->DLM = MSB(pclk / 16 / baudrate); LPC_UART0->DLL = LSB(pclk / 16 / baudrate); //Clear DLAB LPC_UART0->LCR &= ~LCR_DLAB; //Enable and reset FIFOs LPC_UART0->FCR = FCR_TX_FIFO_RESET | FCR_RX_FIFO_RESET | FCR_FIFO_ENABLE; }
/** Performs the specified General Purpose Input/Output (GPIO) operation. @param operation which GPIO operation to do: GPIO_SET_DIRECTION, GPIO_SET_INPUT_MODE, GPIO_SET, GPIO_CLEAR, GPIO_TOGGLE, GPIO_READ @param value the value to write @return the value returned by the ZNP if operation = GPIO_READ; indeterminate value otherwise @post znpResult contains the error code, or ZNP_SUCCESS if success. */ unsigned char sysGpio(unsigned char operation, unsigned char value) { if (operation > 5) { znpResult = -1; return 0; } if ((value > 0x0F) && (operation != GPIO_SET_INPUT_MODE)) { znpResult = -2; return 0; } znpBuf[0] = SYS_GPIO_PAYLOAD_LEN; znpBuf[1] = MSB(SYS_GPIO); znpBuf[2] = LSB(SYS_GPIO); znpBuf[3] = operation; znpBuf[4] = value; znpResult = sendMessage(); return znpBuf[SRSP_PAYLOAD_START]; }
/** * @brief Create content hash key for a byte array * * Create a content hash key for the given buffer and size. * * @param key pointer to the receiving chkey_t * @param buff byte array of data to hash * @param size size of byte array to has * * @result zero on success */ int key_chk(chkey_t *key, const void *buff, size_t size) { key_state_t ks; FUN("key_chk"); sha1_init(&ks.ss); sha1_append(&ks.ss, buff, size); sha1_finish(&ks.ss, &key->sha1); key->log2size = log2size(size); key->type[0] = MSB(K_CHK); key->type[1] = LSB(K_CHK); ek5_init(&ks.es); ek5_append(&ks.es, buff, size); ek5_finish(&ks.es, &key->ek5); key->padding = 0; return 0; }
/** * @brief Create the public SSK for a private SSK * * Create a public key from a private key, * simply by hashing the hex string of the SHA1 digest. * * @param key pointer to a key to receive the public SSK * @param ssk pointer to a key containing a private SSK * * @result zero on success */ int key_ssk_pub_from_priv(chkey_t *key, const chkey_t *ssk) { char hex[SHA1SIZE*2+1]; sha1_state_t sha1; size_t size; FUN("key_ssk_pub_from_priv"); size = pm_snprintf(hex, sizeof(hex), "%s", sha1_hexstr(&ssk->sha1)); sha1_init(&sha1); sha1_append(&sha1, hex, size); sha1_finish(&sha1, &key->sha1); key->type[0] = MSB(K_SSK_P); key->type[1] = LSB(K_SSK_P); key->log2size = log2size(size); memset(&key->ek5, 0, sizeof(key->ek5)); return 0; }
static int s_os(uint8_t type, CalcHandle *handle, uint16_t addr, uint8_t page, uint8_t flag, uint32_t size, uint8_t *data) { DUSBVirtualPacket* pkt; int retval = 0; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(data); pkt = dusb_vtl_pkt_new_ex(handle, 4 + size, type, dusb_vtl_pkt_alloc_data(4 + size)); pkt->data[0] = MSB(addr); pkt->data[1] = LSB(addr); pkt->data[2] = page; pkt->data[3] = flag; memcpy(pkt->data+4, data, size); retval = dusb_send_data(handle, pkt); dusb_vtl_pkt_del(handle, pkt); ticalcs_info(" addr=%04x, page=%02x, flag=%02x, size=%04x", addr, page, flag, size); return retval; }
void EEPROMWrite(WORD addr, BYTE length, BYTE __xdata *buf){ BYTE i; while (I2CS & bmSTOP); // wait for transfer end I2CS |= bmSTART; EEsendData(0xA2); // send I2C address b'10100010 EEsendData(MSB(addr)); // send message to EEPROM EEsendData(LSB(addr)); if (length > 32) length = 32; // send only 32 bytes for(i=0; i<length; i++) { // send data EEsendData(buf[i]); } I2CS |= bmSTOP; // send stop // data processing, wait for EEPROM write while (I2CS & bmSTOP); // wait for transfer end //ack pooling: do { I2CS |= bmSTART; EEsendData(0xA2); } while(!(I2CS & bmACK)); }
/****************************************************************************** * Function: void USBCtrlTrfRxService(void) * * PreCondition: pDst and wCount are setup properly. * pSrc is always &CtrlTrfData * usb_stat.ctrl_trf_mem is always _RAM. * wCount should be set to 0 at the start of each control * transfer. * * Input: None * * Output: None * * Side Effects: None * * Overview: *** This routine is only partially complete. Check for * new version of the firmware. * * Note: None *****************************************************************************/ void USBCtrlTrfRxService(void) { WORD byte_to_read; MSB(byte_to_read) = 0x03 & ep0Bo.Stat._byte; // Filter out last 2 bits LSB(byte_to_read) = ep0Bo.Cnt; /* * Accumulate total number of bytes read */ wCount._word = wCount._word + byte_to_read._word; pSrc.bRam = (byte*)&CtrlTrfData; while(byte_to_read._word) { *pDst.bRam = *pSrc.bRam; pDst.bRam++; pSrc.bRam++; byte_to_read._word--; }//end while(byte_to_read._word) }//end USBCtrlTrfRxService
void setup_gpif_waveforms(void) { BYTE i; // use dual autopointer feature... AUTOPTRSETUP = 0x07; // inc both pointers, // ...warning: this introduces pdata hole(s) // ...at E67B (XAUTODAT1) and E67C (XAUTODAT2) // source AUTOPTRH1 = MSB( &WaveData ); AUTOPTRL1 = LSB( &WaveData ); // destination AUTOPTRH2 = 0xE4; AUTOPTRL2 = 0x00; // transfer for ( i = 0x00; i < 128; i++ ) { EXTAUTODAT2 = EXTAUTODAT1; } }
void QHY8::ConvertDataBIN44(unsigned char * Data,int x, int y, unsigned short PixShift) { unsigned char * Buf = NULL; unsigned int pixel; Buf=(unsigned char *) malloc(x*y*2); long s,k; s=PixShift*2; k=0; while(k < x*y*2) { pixel=Data[s]*256+Data[s+1]+Data[s+2]*256+Data[s+3]; if (pixel>65535) pixel=65535; Buf[k]=LSB(pixel); Buf[k+1]=MSB(pixel); s=s+4; k=k+2; } memcpy(Data,Buf,x*y*2); free(Buf); }