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 mrf24j40_handle_isr() {

uns8 intstat;

	// first we need to get a copy of intstat to find out what happened
	intstat = mrf24j40_short_addr_read(INTSTAT);
	
	// mrf24j40 intstat register is cleared on read
	if (test_bit(intstat, INTSTAT_RXIF)) {
	        #ifndef __PIC32MX__
        		serial_print_str("R");
                #endif        		
		// handle receive
		mrf24j40_receive_callback();
	}
	if (test_bit(intstat, INTSTAT_TXNIF)) {
	        #ifndef __PIC32MX__	
        		serial_print_str("Tx complete txstat=0x");
        	#endif	
		uns8 stat = mrf24j40_short_addr_read(TXSTAT);
		mrf24j40_transmit_callback(stat & 0b00000001,	// success = 0
		                                  stat >> 6,	// retries
		                                  test_bit(stat, TXSTAT_CCAFAIL)); // due to cca failure?
	        #ifndef __PIC32MX__		                                  
        		serial_print_int_hex(stat);
	        	serial_print_nl();
                #endif	        	
	}

}	
void mrf24j40_set_extended_address(uns8 *_extended_address) {
	uns8 count;
	uns8 mem_pos = EADR7;
	#ifndef __PIC32MX__
        	serial_print_str("Setting EA to: ");
    #endif        	
	for (count = 0; count < 8; count++) {
		extended_address[count] = _extended_address[count];
		mrf24j40_short_addr_write(mem_pos--, extended_address[count]);
		#ifndef __PIC32MX__
        		serial_print_int_hex(extended_address[count]);
	        	serial_putc(' ');
	    #endif	
	}
	#ifndef __PIC32MX__
        	serial_print_nl();
    #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	
	}
}
Exemple #5
0
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	
}