inline void transmit(void) { // Power up radio. RADIO_POWER_PORT |= _BV(RADIO_POWER_PIN); DDRB |= _BV(TX_PIN); _delay_ms(0.1); manchester_union.manchester_packet.checksum = calculate_checksum(&manchester_union.manchester_packet); // Transmit preamble for (int i = 4; i > 0; i--) { transmit_byte(0xFF); } transmit_byte(0x7F); // Transmit data int len = sizeof(manchester_union); for (int i = 0; i < len; i++) { char b = manchester_union.manchester_data[i]; transmit_byte(b); } // Generate one final transition TX_PORT ^= (char)_BV(TX_PIN); _delay_ms(HALF_BIT_DELAY_TIME_MILLIS); // Then disable the transmitter RADIO_POWER_PORT &= ~_BV(RADIO_POWER_PIN); // And tri-state the TX pin DDRB &= (char)~_BV(TX_PIN); TX_PORT &= (char)~_BV(TX_PIN); }
void qx10_keyboard_device::received_byte(uint8_t data) { switch (data & 0xe0) { case 0x00: // set repeat start break; case 0x20: // set repeat interval break; case 0x40: // set LED break; case 0x60: // get LED transmit_byte(0); break; case 0x80: // get SW break; case 0xa0: // set repeat break; case 0xc0: // enable keyboard break; case 0xe0: if (!(data & 1)) transmit_byte(0); break; } }
void apricot_keyboard_hle_device::received_byte(uint8_t byte) { if ((byte & 0xf0) == 0xf0) { // rtc data if (m_rtc_index >= 0) { m_rtc->address_w(m_rtc_index--); m_rtc->data_w(machine().dummy_space(), 0, byte); m_rtc->write_w(1); m_rtc->write_w(0); } } else { switch (byte) { case CMD_REQ_TIME_AND_DATE: logerror("System requests current time\n"); // remove pending keys just in case clear_fifo(); // send time prefix transmit_byte(0xed); // make rtc chip ready m_rtc->cs_w(1); m_rtc->read_w(1); // send bcd encoded date and time to system for (int i = 12; i >= 0; i--) { m_rtc->address_w(i); transmit_byte(0xf0 | m_rtc->data_r(machine().dummy_space(), 0)); } break; case CMD_SET_TIME_AND_DATE: logerror("System requests to set time\n"); // we start with the year m_rtc_index = 12; // make rtc chip ready m_rtc->cs_w(1); break; case CMD_KEYBOARD_RESET: logerror("System requests keyboard reset\n"); transmit_byte(ACK_DIAGNOSTICS); break; default: logerror("Unhandled command: %02x\n", byte); } } }
void m20_keyboard_device::received_byte(UINT8 byte) { switch (byte) { case 0x03U: transmit_byte(0x02U); break; case 0x80U: transmit_byte(0x80U); break; default: logerror("received unknown command %02x", byte); } }
void send_string(const char *str) { while(*str) { transmit_byte(*str++); } }
int transfer_start(I2C_MODULE port, I2C_7_BIT_ADDRESS address, UINT8 rw) { I2C_STATUS status; int result = 0; while(!I2CBusIsIdle(port)); if(I2CStart(port) != I2C_SUCCESS) return -1; do { status = I2CGetStatus(port); } while(!(status & I2C_START)); /* Send address */ address.rw = rw; result = transmit_byte(port, address.byte); if(result < 0) return result; if(!I2CByteWasAcknowledged(port)) return -1; return result; }
int main (void) { // setup debug port DDRD = 0xFF; PORTD= 0xFF; // setup led panel for writing (output) DDRB = 0xFF; // main loop unsigned int line = 0; while(1) { // clear port PORTB = 0; int leds_used = 0; // transmit last byte first, starting with a potentially padded byte int last_byte_idx = g_image_width_in_bytes -1 + line*g_image_width_in_bytes; if( g_image_width_padding != 0) // padded byte? { // padding found, so shift byte to first not padded bit Byte last = g_image[ last_byte_idx ]; last.data >>= g_image_width_padding; // transmit now accurate bits transmit_some_bits( last, 8 - g_image_width_padding ); leds_used += 8 - g_image_width_padding; // set last index to the last but one (since the last one was just used) last_byte_idx --; } // send all remaining bytes unsigned start_byte_idx = (line-1)*g_image_width_in_bytes; if( line == 0) { start_byte_idx = 0; } for( unsigned u = start_byte_idx; u < last_byte_idx; ++u) { transmit_byte( g_image[ u ]); leds_used += 8; } // add empty bits if needet Byte b; b.data = 0; transmit_some_bits( b, LED_BAR_SIZE - leds_used); // line completed PORTB = 1 << 1; // show leds _delay_ms(DELAY); line ++; line = line % g_image_height; }
void send_byte_with_handshake(unsigned char byte) { transmit_byte(byte); signal_byte_ready(); wait_for_remote_ready(); signal_byte_not_ready(); wait_for_remote_notready(); }
void octopus_keyboard_device::key_make(uint8_t row, uint8_t column) { if (row != 0x0eU) typematic_start(row, column, attotime::from_msec(m_delay), attotime::from_msec(m_repeat)); else typematic_restart(attotime::from_msec(m_delay), attotime::from_msec(m_repeat)); transmit_byte((row << 3) | column); }
/* * Start transmitting a byte. * Assume the transmitter is stopped, and the transmit queue is not empty. * Return 1 when we are expecting the hardware interrupt. */ static bool_t slip_transmit_start (slip_t *u) { unsigned char c; /* Check that transmitter buffer is busy. */ if (! test_transmitter_empty (u->port)) return 1; /* Nothing to transmit or no CTS - stop transmitting. */ if ((! u->out_flag && ! u->out) || ! slip_get_cts (u)) { /* Disable `transmitter empty' interrupt. */ disable_transmit_interrupt (u->port); return 0; } if (u->out_flag) { c = SLIP_FLAG; u->out_flag = 0; } else { c = *u->out_first; switch (c) { case SLIP_FLAG: c = SLIP_ESC; *u->out_first = SLIP_ESC_FLAG; break; case SLIP_ESC: c = SLIP_ESC; *u->out_first = SLIP_ESC_ESC; break; default: ++u->out_first; break; } if (u->out_first >= u->out_limit) { u->outseg = u->outseg->next; if (u->outseg) { u->out_first = u->outseg->payload; u->out_limit = u->outseg->payload + u->outseg->len; } else { /* Last segment transmitted. */ ++u->netif.out_packets; u->netif.out_bytes += u->out->tot_len; debug_printf ("slip: transmitted %d bytes\n", u->out->tot_len); u->out_free = u->out; u->out = 0; u->out_flag = 1; } } } transmit_byte (u->port, c); /* Enable `transmitter empty' interrupt. */ enable_transmit_interrupt (u->port); return 1; }
void x68k_keyboard_device::key_make(uint8_t row, uint8_t column) { // TODO: work out which keys actually repeat (this assumes it's anything other than ctrl/opt/shift) if (row != 0x0eU) typematic_start(row, column, attotime::from_msec(m_delay), attotime::from_msec(m_repeat)); else typematic_restart(attotime::from_msec(m_delay), attotime::from_msec(m_repeat)); transmit_byte((row << 3) | column); }
void init() { // set port register a to output for bit 2 unsigned char reg = CIA2.ddra; // raise bit 2 reg = reg | PA2; CIA2.ddra = reg; signal_byte_not_ready(); set_userport_output(); transmit_byte(0x00); set_border_color(0); }
/** * @brief Reads multiple blocks from the SD card and send every block to UART * @return unsigned char - 0 if no error and response byte if error */ unsigned char sd_read_multiple_blocks (unsigned long start_block, unsigned long total_blocks) { unsigned char response; unsigned int i, retry = 0; retry = 0; response = sd_send_command(READ_MULTIPLE_BLOCKS, start_block); //write a Block command if(response != 0x00) return response; //check for SD status: 0x00 - OK (No flags set) SD_CS_ASSERT; while(total_blocks) { retry = 0; while(spi_receive() != 0xfe) //wait for start block token 0xfe (0x11111110) if(retry++ > 0xfffe) { SD_CS_DEASSERT; return 1; } //return if time-out for(i = 0; i < 512; i++) //read 512 bytes buffer[i] = spi_receive(); spi_receive(); //receive incoming CRC (16-bit), CRC is ignored here spi_receive(); spi_receive(); //extra 8 cycles for(i = 0; i < 512; i++) //send the block to UART { if(buffer[i] == '~') break; transmit_byte(buffer[i]); } total_blocks--; } sd_send_command(STOP_TRANSMISSION, 0); //command to stop transmission SD_CS_DEASSERT; spi_receive(); //extra 8 clock pulses return 0; }
int main () { uint8_t i; usart_init (BRR_VAL); max6675_init (); while (1) { buffer (readCelsius()); for (i=0;i<4;++i) { transmit_byte (buff[i]); } _delay_ms (500); } }
void m20_keyboard_device::key_make(UINT8 row, UINT8 column) { UINT8 const row_code(((row < 6U) ? row : (0x18U | (row - 6U))) << 3); UINT8 const modifiers(m_modifiers->read()); UINT8 mod_code(0U); switch (modifiers) { case 0x01U: // COMMAND mod_code = 0x90; break; case 0x02U: // CTRL mod_code = 0x60; break; case 0x04U: // RSHIFT case 0x08U: // LSHIFT case 0x0cU: // LSHIFT|RSHIFT mod_code = 0x30; break; } transmit_byte((row_code | column) + mod_code); }
int gestic_message_write(gestic_t *gestic, void *msg, int size) { I2C_MODULE port = gestic->io.I2cPort; const unsigned char * const buffer = (unsigned char*)msg; int result = 0; int i; GESTIC_ASSERT(buffer[0] == size); if(transfer_start(port, gestic->io.I2cSlaveAddr, 0)) result = -1; for(i = 0; !result && i < size; ++i) { if(transmit_byte(port, buffer[i]) < 0) result = -1; if(!I2CByteWasAcknowledged(port)) result = -1; } transfer_stop(port); return result; }
void serial_terminal_device::send_key(uint8_t code) { transmit_byte(code); }
/** * @brief Recieves data from UART and writes to multiple blocks of SD card * @return unsigned char - response byte */ unsigned char sd_write_multiple_blocks(unsigned long start_block, unsigned long total_blocks) { unsigned char response, data; unsigned int i, retry = 0; unsigned long block_counter = 0, size; response = sd_send_command(WRITE_MULTIPLE_BLOCKS, start_block); //write a Block command if(response != 0x00) return response; //check for SD status: 0x00 - OK (No flags set) SD_CS_ASSERT; while( block_counter < total_blocks ) { i = 0; do { data = receive_byte(); if(data == 0x08) //'Back Space' key pressed { if(i != 0) { transmit_byte(data); transmit_byte(' '); transmit_byte(data); i--; size--; } continue; } transmit_byte(data); buffer[i++] = data; if(data == 0x0d) { transmit_byte(0x0a); buffer[i++] = 0x0a; } if(i == 512) break; } while (data != '~'); spi_transmit(0xfc); //Send start block token 0xfc (0x11111100) for(i = 0; i < 512; i++) //send 512 bytes data spi_transmit(buffer[i]); spi_transmit(0xff); //transmit dummy CRC (16-bit), CRC is ignored here spi_transmit(0xff); response = spi_receive(); if((response & 0x1f) != 0x05) //response= 0xXXX0AAA1 ; AAA='010' - data accepted { //AAA='101'-data rejected due to CRC error SD_CS_DEASSERT; //AAA='110'-data rejected due to write error return response; } while(!spi_receive()) //wait for SD card to complete writing and get idle if(retry++ > 0xfffe) { SD_CS_DEASSERT; return 1; } spi_receive(); //extra 8 bits block_counter++; } spi_transmit(0xfd); //send 'stop transmission token' retry = 0; while(!spi_receive()) //wait for SD card to complete writing and get idle if(retry++ > 0xfffe) { SD_CS_DEASSERT; return 1; } SD_CS_DEASSERT; spi_transmit(0xff); //just spend 8 clock cycle delay before reasserting the CS signal // re assertion of the CS signal is required to verify if card is still busy SD_CS_ASSERT; while(!spi_receive()) //wait for SD card to complete writing and get idle if(retry++ > 0xfffe) { SD_CS_DEASSERT; return 1; } SD_CS_DEASSERT; return 0; }
void rmnimbus_keyboard_device::key_make(UINT8 row, UINT8 column) { transmit_byte((row << 3) | column); }
void octopus_keyboard_device::key_break(uint8_t row, uint8_t column) { device_matrix_keyboard_interface::key_break(row, column); transmit_byte(0x80U | (row << 3) | column); }
void octopus_keyboard_device::key_repeat(uint8_t row, uint8_t column) { transmit_byte((row << 3) | column); }
void rmnimbus_keyboard_device::key_break(UINT8 row, UINT8 column) { transmit_byte(0x80U | (row << 3) | column); }
// //====================================================================================================== int main ( void ) { int ret; char str[] = "Lena I want to make your life more happy."; char* byte; __u8 reg; __u64 data = 0; byte = str; ret = init_n_rf24l01(); if( ret < 0 ) return 1; prepare_to_transmit(); while( 1 ) { printf( "transmit %c.\n", *byte ); data = (__u64)*byte; send_command( W_TX_PAYLOAD, NULL, &data, 1, 1 ); // CE up... sleep 10 us... CE down - to actual data transmit (in space) set_up_ce_pin( 1 ); usleep( 10 ); set_up_ce_pin( 0 ); // round-robin buffer if( *(++byte) == 0 ) { byte = str; } wait_pkg_transmitted(); sleep( 1 ); } read_register( CONFIG_RG, ® ); read_register( STATUS_RG, ® ); send_command( W_TX_PAYLOAD, NULL, (__u64*)"9", 1, 1 ); read_register( STATUS_RG, ® ); clear_pending_interrupts(); read_register( STATUS_RG, ® ); prepare_to_receive(); while(1) { read_register( STATUS_RG, ® ); if( reg != 0x0e ) { send_command( R_RX_PAYLOAD, NULL, &data, 1, 0 ); clear_pending_interrupts(); } } ret = prepare_to_transmit(); if( ret < 0 ) return 1; read_register( CONFIG_RG, ® ); printf( "before while(1): CONFIG_RG: 0x%02hhx.\n", reg ); read_register( STATUS_RG, ® ); printf( "before while(1): STATUS_RG: 0x%02hhx.\n", reg ); set_up_ce_pin( 1 ); usleep( 10 ); //set_up_ce_pin( 0 ); while( 1 ) { send_command( W_TX_PAYLOAD, NULL, (__u64*)byte++, 1, 1 ); printf( "byte %c has been transmitted to space.\n", *(byte - 1) ); // round-robin buffer to transmit if( *byte == '\0' ) byte = str; sleep(1); } // we transmit one byte one time in second while( 1 ) { ret = transmit_byte( *byte++ ); if( ret < 0) return 0; printf( "byte %c has been transmitted to space.\n", *(byte - 1) ); // round-robin buffer to transmit if( *byte == '\0' ) byte = str; } return 0; }
void apricot_keyboard_hle_device::key_make(uint8_t row, uint8_t column) { // send the make code transmit_byte((row << 3) | column); }
void apricot_keyboard_hle_device::key_break(uint8_t row, uint8_t column) { // send the break code transmit_byte(0x80 | (row << 3) | column); }
void qx10_keyboard_device::key_make(uint8_t row, uint8_t column) { transmit_byte((column << 4) | row); }