// ====================================================================== // JVdG USB Gadget Firmware // // Copyright 2011 Julien Viard de Galbert // // based on: // USBtiny template application // // Copyright 2006-2010 Dick Streefland // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, // MA 02110-1301, USA. // ====================================================================== #include "usb.h" #include enum { // Generic requests USBTINY_ECHO, // echo test USBTINY_READ, // read byte USBTINY_WRITE, // write byte }; static volatile byte_t mux_sel; // ---------------------------------------------------------------------- // Handle a non-standard SETUP packet. // ---------------------------------------------------------------------- extern byte_t usb_setup ( byte_t data[8] ) { byte_t req; // Generic requests req = data[1]; if ( req == USBTINY_ECHO ) { return 8; } // LED PORTC0-3 if ( req == USBTINY_READ ) { data[0] = mux_sel; return 1; } if ( req == USBTINY_WRITE ) { mux_sel = data[2] & 1; return 0; } return 0; } // ---------------------------------------------------------------------- // Handle an IN packet. (USBTINY_CALLBACK_IN==1) // ---------------------------------------------------------------------- extern byte_t usb_in ( byte_t* data, byte_t len ) { return 0; } // ---------------------------------------------------------------------- // Handle an OUT packet. (USBTINY_CALLBACK_OUT==1) // ---------------------------------------------------------------------- extern void usb_out ( byte_t* data, byte_t len ) { } // ---------------------------------------------------------------------- // Main // ---------------------------------------------------------------------- extern int main ( void ) { // my init // PB2-3 led output PORTB &= ~(1 << PB3); PORTB |= (1 << PB2); DDRB |= (1 << PB2) | (1 << PB3); // PB0-1 key in with pull up DDRB &= ~((1 << PB0) | (1 << PB1)); PORTB |= (1 << PB0) | (1 << PB1); mux_sel = 0; usb_init(); for ( ;; ) { usb_poll(); if( ~PINB & (1 << PB0)) { mux_sel = 0; } else if ( ~PINB & (1 << PB1)) { mux_sel = 1; } if (mux_sel) { PORTB &= ~(1 << PB2); PORTB |= (1 << PB3); } else { PORTB &= ~(1 << PB3); PORTB |= (1 << PB2); } } }