void usb_handle_class_ctrl_write_callback(uns8 *data, uns16 count) { switch (usb_sdp.bRequest) { case req_SET_LINE_CODING: // dump it into class_data memcpy(/* dst */ (void *)&class_data,/* src */ (void *)data, count); // Now we need to send an ACK status back control_mode = cm_CTRL_WRITE_SENDING_STATUS; usb_send_status_ack(); line_coding *my_lc; my_lc = (line_coding*) &class_data; #ifdef CDC_DEBUG serial_print_int_hex(my_lc->dte_rate.as_byte_array[0]); serial_print_int_hex(my_lc->dte_rate.as_byte_array[1]); serial_print_int_hex(my_lc->dte_rate.as_byte_array[2]); serial_print_int_hex(my_lc->dte_rate.as_byte_array[3]); serial_print_str(" st="); serial_print_int(my_lc->stop_bits); serial_print_str(" p="); serial_print_int(my_lc->parity); serial_print_str(" db="); serial_print_int(my_lc->data_bits); #endif break; default: #ifdef CDC_DEBUG serial_print_str(" ??ctrl write cb req="); serial_print_int_hex(usb_sdp.bRequest); serial_putc(' '); #endif break; } }
void usb_ep_data_out_callback(uns8 end_point, uns8 *buffer, uns16 byte_count) { uns8 cdc_rx_next; #ifdef CDC_DEBUG serial_print_str(" EP data out: "); serial_print_int(byte_count); serial_print_str(" bytes "); #endif // We have some data! if (end_point == USB_CDC_DATA_ENDPOINT) { // it's the data end point uns8 count; for (count = 0; count < byte_count; count++) { cdc_rx_next = cdc_rx_end + 1; // get next buffer position if (cdc_rx_next == USB_CDC_RX_BUFFER_SIZE) { // if we're at the end cdc_rx_next = 0; // then wrap to the beginning } if (cdc_rx_next != cdc_rx_start) { // if space in the fifo cdc_rx_buffer[cdc_rx_end] = buffer[count]; // put it in cdc_rx_end = cdc_rx_next; // and move pointer along } // else... just ignore it, we've lost a byte, no room in the inn } } else { #ifdef CDC_DEBUG serial_print_str("data for ep "); serial_print_int(end_point); #endif } }
void usb_handle_class_request_callback(setup_data_packet sdp) { switch (sdp.bRequest) { case req_SET_LINE_CODING: // we now expect the line coding to arrive in the data stage #ifdef CDC_DEBUG serial_print_str("SET_LINE "); #endif control_mode = cm_CTRL_WRITE_DATA_STAGE_CLASS; break; case req_GET_LINE_CODING: #ifdef CDC_DEBUG serial_print_str("GET_LINE "); serial_print_str(" len="); serial_print_int(sdp.wLength); serial_putc(' '); #endif //control_mode = cm_CTRL_READ_DATA_STAGE_CLASS; control_mode = cm_CTRL_READ_DATA_STAGE_CLASS; // need to prime ep0 IN with some funky data here usb_send_data(/*ep*/ 0, /*data*/ &class_data, /*count*/ 7, /*first*/ 1); // actually we know this will be the last packet, so go straight to waiting for the status ack control_mode = cm_CTRL_READ_AWAITING_STATUS; break; case req_SET_CONTROL_LINE_STATE: #ifdef CDC_DEBUG serial_print_str("scls=");//dtr = bit 0, rts = bit 1 serial_print_int_hex(sdp.wValue); #endif // no data, so just ack the status control_mode = cm_CTRL_WRITE_SENDING_STATUS; usb_send_status_ack(); // Could put a callback here for your own code when DTR or RTS change break; default: #ifdef CDC_DEBUG serial_print_str("??r="); serial_print_int(sdp.bRequest); #endif } }
void usb_ep_data_in_callback(uns8 end_point, uns16 byte_count) { #ifdef CDC_DEBUG serial_print_str(" EP data in: "); serial_print_int(byte_count); serial_print_str(" bytes "); #endif // data has been sent, so do we need to send more? if (end_point == USB_CDC_DATA_ENDPOINT) { // it's the data end point usb_cdc_handle_tx(); } }
void usb_handle_class_ctrl_read_callback() { switch (usb_sdp.bRequest) { case req_GET_LINE_CODING: // we know we've already sent everything, so now wait for status control_mode = cm_CTRL_READ_AWAITING_STATUS; break; default: #ifdef CDC_DEBUG serial_print_str(" cl read ?? "); serial_print_int(usb_sdp.bRequest); #endif } }
void draw_print_buffer() { #ifdef DRAW_DEBUG uns8 inv_y, x , y, byte_loc, bit_loc; uns16 buffer_loc; for(y = 0 ; y < DRAW_PIXELS_HIGH ; y++) { inv_y = DRAW_PIXELS_HIGH - 1 - y; // need to print out from the top if (inv_y < 10) { serial_putc('0'); } serial_print_int(inv_y); serial_putc(' '); serial_print_int_hex(inv_y * DRAW_PIXELS_WIDE / DRAW_PIXELS_PER_BYTE); serial_putc('|'); for(x = 0 ; x < DRAW_PIXELS_WIDE ; x++) { buffer_loc = inv_y * DRAW_PIXELS_WIDE + x; byte_loc = buffer_loc / DRAW_PIXELS_PER_BYTE; bit_loc = buffer_loc & (DRAW_PIXELS_PER_BYTE -1); //if (bit_loc == 0) { // serial_putc(' '); // serial_print_int_hex(byte_loc); // serial_putc(' '); //} if (test_bit(draw_buffer0[byte_loc], bit_loc)) { serial_putc('1'); } else { serial_putc('0'); } } serial_print_str("|\n"); } #endif }
void usb_handle_class_request(setup_data_packet sdp){ #ifdef USB_DEBUG serial_print_str("Class request: "); serial_print_int(sdp.bRequest); #endif switch(sdp.bRequest){ case req_GET_REPORT: break; case req_GET_IDLE: break; case req_GET_PROTOCOL: break; case req_SET_REPORT: break; case req_SET_IDLE: // we don't support whatever they want usb_stall_ep0(); break; case req_SET_PROTOCOL: break; } }
void usb_handle_class_request_callback(setup_data_packet sdp) { serial_print_str("Class request: "); serial_print_int(sdp.bRequest); switch(sdp.bRequest) { case req_GET_REPORT: break; case req_GET_IDLE: break; case req_GET_PROTOCOL: break; case req_SET_REPORT: break; case req_SET_IDLE: serial_print_str(" Set_idle "); // we don't support whatever they want usb_stall_ep0(); break; case req_SET_PROTOCOL: break; } }
void main() { configure_system(); delay_ms(100); serial_print_str("\n\nPicPack Sure 2416 Led display demo\n"); serial_print_str( "\n<"); serial_print_str(__TIME__); serial_putc(' '); serial_print_str(__DATE__); serial_print_str(">\n"); delay_ms(100); // sure_2416_write(0,0b00001111); uns8 brightness = 0; uns8 my_count = 0; while (1) { //delay_ms(250); //serial_print_str("writing...\n"); //sure_2416_write(0,0b00001111); /*delay_s(5); sure_2416_set_pixel(0,0,1); delay_s(1); sure_2416_set_pixel(23,0,1); delay_s(1); sure_2416_set_pixel(23,15,1); delay_s(1); sure_2416_set_pixel(0,15,1); delay_s(1); sure_2416_set_pixel(0,0,0); delay_s(1); sure_2416_set_pixel(23,0,0); delay_s(1); sure_2416_set_pixel(23,15,0); delay_s(1); sure_2416_set_pixel(0,15,0);*/ /*uns8 x,y; for(x = 0 ; x < 24 ; x++) { for(y = 0 ; y < 16 ; y++) { sure_2416_set_pixel(x, y, 1); } } delay_ms(100); for(x = 0 ; x < 24 ; x++) { for(y = 0 ; y < 16 ; y++) { sure_2416_set_pixel(x, y, 0); } } delay_ms(100); */ sure_2416_fill2(0); delay_ms(100); sure_2416_fill2(1); delay_ms(100); my_count++; if (my_count == 10) { serial_print_str("Setting brightness to "); serial_print_int(brightness); serial_print_nl(); sure_2416_set_brightness(brightness++); if (brightness == 16) { brightness = 0; } my_count = 0; } } } // main
void usb_cdc_handle_tx() { uns8 cdc_tx_next; uns8 count; uns16 buffer_size; uns8 *buffer; buffer_descriptor *bd; bd = ep_in_bd_location[USB_CDC_DATA_ENDPOINT]; if (test_bit(bd->stat, UOWN)) { // if there's already something in play return; // give up } buffer_size = ep_in_buffer_size[USB_CDC_DATA_ENDPOINT]; buffer = ep_in_buffer_location[USB_CDC_DATA_ENDPOINT]; if (cdc_tx_end == cdc_tx_start) { // anything in the fifo? return; // nope } #ifdef CDC_DEBUG serial_putc('<'); #endif start_crit_sec(); count = 0; while ((cdc_tx_end != cdc_tx_start) && (count < buffer_size)) { cdc_tx_next = cdc_tx_start + 1; // get next position if (cdc_tx_next == USB_CDC_TX_BUFFER_SIZE) { // if we're at the end of the buffer cdc_tx_next = 0; // wrap to the beginning } buffer[count] = cdc_tx_buffer[cdc_tx_start]; // transmit the character #ifdef CDC_DEBUG serial_putc(buffer[count]); #endif count++; cdc_tx_start = cdc_tx_next; // move start position of fifo } if (count > 0) { bd->count = count; bd->addr = (uns16)buffer; toggle_bit(bd->stat, DTS); clear_bit(bd->stat, KEN); // clear the keep bit clear_bit(bd->stat, INCDIS); // clear the increment disable set_bit (bd->stat, DTSEN); clear_bit(bd->stat, BSTALL); // clear stall bit clear_bit(bd->stat, BC9); clear_bit(bd->stat, BC8); set_bit (bd->stat, UOWN); // SIE owns the buffer } end_crit_sec(); #ifdef CDC_DEBUG serial_putc('>'); serial_print_str("send="); serial_print_int(count); serial_putc(' '); #endif }
void main() { trisa = 0; flash(); configure_system(); flash(); delay_ms(100); serial_print_str("\n\nPicPack Sure 6432 Led display demo\n"); serial_print_str( "\n<"); serial_print_str(__TIME__); serial_putc(' '); serial_print_str(__DATE__); serial_print_str(">\n"); serial_print_str("total buffer = "); serial_print_int(DRAW_TOTAL_BUFFER_SIZE); serial_print_nl(); serial_print_str("wide = "); serial_print_int(DRAW_PIXELS_WIDE); serial_print_nl(); serial_print_str("high = "); serial_print_int(DRAW_PIXELS_HIGH); serial_print_nl(); serial_print_str("ppb = "); serial_print_int(DRAW_PIXELS_PER_BYTE); serial_print_nl(); while (1) { /*delay_ms(250); draw_set_pixel(0,0,1); draw_paint(); delay_s(1); draw_set_pixel(23,0,1); draw_paint(); delay_s(1); draw_set_pixel(23,15,1); draw_paint(); delay_s(1); draw_set_pixel(0,15,1); draw_paint(); delay_s(1); draw_set_pixel(0,0,0); draw_paint(); delay_s(1); draw_set_pixel(23,0,0); draw_paint(); delay_s(1); draw_set_pixel(23,15,0); draw_paint(); delay_s(1); draw_set_pixel(0,15,0); draw_paint(); delay_s(1); draw_line(0, 0, 23, 15, 1); draw_paint(); delay_s(1); draw_line(0, 15, 23, 0, 1); draw_paint(); delay_s(1); draw_line(0, 0, 23, 15, 0); draw_paint(); delay_s(1); draw_line(0, 15, 23, 0, 0); draw_paint(); delay_s(1); draw_circle(12, 8, 1, 1); draw_paint(); delay_s(1); draw_circle(12, 7, 2, 1); draw_paint(); delay_s(1); draw_circle(12, 7, 3, 1); draw_paint(); delay_s(1); draw_circle(12, 7, 4, 1); draw_paint(); delay_s(1); draw_circle(12, 7, 5, 1); draw_paint(); delay_s(1); draw_circle(12, 7, 6, 1); draw_paint(); delay_s(1); draw_circle(12, 7, 7, 1); draw_paint(); delay_s(1);*/ draw_clear_screen(); serial_print_str("Rectangle\n"); draw_rect(1, 1, DRAW_PIXELS_WIDE - 1 -1 , DRAW_PIXELS_HIGH - 1 - 1, 2); /*draw_set_pixel(0,0,1); draw_set_pixel(DRAW_PIXELS_WIDE - 1, 0, 1); draw_set_pixel(DRAW_PIXELS_WIDE - 1, DRAW_PIXELS_HIGH - 1, 1); draw_set_pixel(0, DRAW_PIXELS_HIGH - 1, 1); */ uns16 countp; for (countp = 0; countp < 200; countp++) { draw_paint(); } draw_clear_screen(); serial_print_str("Rectangle\n"); draw_rect(1, 1, 62, 30, 1); draw_circle(31, 16, 15, 3); for (countp = 0; countp < 1000; countp++) { draw_paint(); } } } // main