From 4caa7ea958fe8cb2c31b5750a380c507ebc382c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Ass=C3=A9nat?= Date: Fri, 26 Apr 2013 12:23:38 +0000 Subject: [PATCH] 1.4.1 Code cleanup --- Changelog.txt | 7 +++++ Makefile.atmega168 | 20 +++++++++++-- fournsnes.c | 1 - leds.h | 18 ------------ main.c | 71 +++++++++++++++++++++++++++------------------- usbconfig.h | 4 +-- 6 files changed, 68 insertions(+), 53 deletions(-) delete mode 100644 leds.h diff --git a/Changelog.txt b/Changelog.txt index a1d8529..4296aef 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,3 +1,10 @@ +--- v1.4.1 (April 26, 2013) +- Reduced declared max current from 120mA to 100mA. This makes +it possible to connect the adapter to my keyboard USB port but +is still a conservative estimate for the worst combination +of hypothetical non-standard power hungry controllers. +- Some code cleanups + --- v1.4 (April 20, 2013) - Support for Atmega168. Use Makefile.atmega168. - New USB VID/PID diff --git a/Makefile.atmega168 b/Makefile.atmega168 index b15115a..9e49b5d 100644 --- a/Makefile.atmega168 +++ b/Makefile.atmega168 @@ -46,19 +46,33 @@ $(HEXFILE): $(ELFFILE) flash: $(HEXFILE) $(AVRDUDE) -Uflash:w:$(HEXFILE) -B 1.0 +# Extended fuse byte (Datasheet Table 28-5) +# # - - - - - BOOTSZ1 BOOTSZ0 BOOTRST # 0 0 0 0 0 0 0 1 +# EFUSE=0x01 +# Fuse high byte (Datasheet Table 28-6) +# # RSTDISBL DWEN SPIEN WDTON EESAVE BODLEVEL2 BODLEVEL1 BODLEVEL0 -# 1 1 0 1 1 1 1 1 +# 1 1 0 1 0 1 0 1 +# HFUSE=0xd5 + +# Fuse low byte (Datasheet Table 28-7) # # CKDIV8 CKOUT SUT1 SUT0 CKSEL3 CKSEL2 CKSEL1 CKSEL0 # 1 1 0 1 0 1 1 1 # -# Full swing crystal oscillator, BOD enabled -LFUSE=0xDF +# Full swing crystal oscillator +# 0.4 - 20 MHz : CKSEL3..1 011 +# +# Crystal Oscillator, BOD enabled (Table 9-6) +# CKSEL0 : 1 +# SUT1..0 : 01 +# +LFUSE=0xD7 fuse: $(AVRDUDE) -e -Uefuse:w:$(EFUSE):m -Uhfuse:w:$(HFUSE):m -Ulfuse:w:$(LFUSE):m -B 20.0 -v diff --git a/fournsnes.c b/fournsnes.c index c54dc08..904ecf3 100644 --- a/fournsnes.c +++ b/fournsnes.c @@ -13,7 +13,6 @@ #include #include #include "gamepad.h" -#include "leds.h" #include "fournsnes.h" #define GAMEPAD_BYTES 8 /* 2 byte per snes controller * 4 controllers */ diff --git a/leds.h b/leds.h deleted file mode 100644 index c47fb0b..0000000 --- a/leds.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef _leds_h__ -#define _leds_h__ - -#ifndef PORTD -#include -#endif - - -#define LED_OFF() -#define LED_ON(); -#define LED_TOGGLE(); - -//#define LED_OFF() do { PORTD |= 0x20; } while(0) -//#define LED_ON() do { PORTD &= ~0x20; } while(0) -//#define LED_TOGGLE() do { PORTD ^= 0x20; } while(0) - -#endif - diff --git a/main.c b/main.c index 32284d1..f5089ae 100644 --- a/main.c +++ b/main.c @@ -18,7 +18,6 @@ #include "fournsnes.h" -#include "leds.h" #include "devdesc.h" static uchar *rt_usbHidReportDescriptor=NULL; @@ -101,32 +100,40 @@ static Gamepad *curGamepad; static void hardwareInit(void) { - uchar i, j; + + /* PORTB + * + * Bit Description Direction Level/pu + * 0 Jumpers common Out 0 + * 1 JP1 In 1 + * 2 JP2 In 1 + * 3 MOSI In 1 + * 4 MISO In 1 + * 5 SCK In 1 + * 6 - + * 7 - + */ + DDRB = 0x01; + PORTB = 0xFE; // init port C as input with pullup DDRC = 0x00; PORTC = 0xff; - - /* 1101 1000 bin: activate pull-ups except on USB lines - * - * USB signals are on bit 0 and 2. - * - * Bit 1 is connected with bit 0 (rev.C pcb error), so the pullup - * is not enabled. - * */ - PORTD = 0xf8; - /* Usb pin are init as outputs */ + /* + * For port D, activate pull-ups on all lines except the D+, D- and bit 1. + * + * For historical reasons (a mistake on an old PCB), bit 1 + * is now always connected with bit 0. So bit 1 configured + * as an input without pullup. + * + * Usb pin are init as output, low. (device reset). They are released + * later when usbReset() is called. + */ + PORTD = 0xf8; DDRD = 0x01 | 0x04; - - j = 0; - while(--j){ /* USB Reset by device only required on Watchdog Reset */ - i = 0; - while(--i); /* delay >10ms for USB reset */ - } - DDRD = 0x00; /* 0000 0000 bin: remove USB reset condition */ - + /* Configure timers */ #if defined(AT168_COMPATIBLE) TCCR2A= (1<>1; @@ -264,8 +278,7 @@ int main(void) // patch the config descriptor with the HID report descriptor size my_usbDescriptorConfiguration[25] = rt_usbHidReportDescriptorSize; - //wdt_enable(WDTO_2S); - hardwareInit(); + usbReset(); curGamepad->init(); usbInit(); diff --git a/usbconfig.h b/usbconfig.h index c8b7556..9272fb4 100644 --- a/usbconfig.h +++ b/usbconfig.h @@ -5,7 +5,7 @@ * Tabsize: 4 * Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH * License: GNU GPL v2 (see License.txt) or proprietary (CommercialLicense.txt) - * This Revision: $Id: usbconfig.h,v 1.9 2013-04-20 17:24:53 cvs Exp $ + * This Revision: $Id: usbconfig.h,v 1.10 2013-04-26 12:23:38 cvs Exp $ */ #ifndef __usbconfig_h_included__ @@ -89,7 +89,7 @@ rename it to "usbconfig.h". Then edit it accordingly. /* Define this to 1 if the device has its own power supply. Set it to 0 if the * device is powered from the USB bus. */ -#define USB_CFG_MAX_BUS_POWER 120 +#define USB_CFG_MAX_BUS_POWER 100 /* Set this variable to the maximum USB bus power consumption of your device. * The value is in milliamperes. [It will be divided by two since USB * communicates power requirements in units of 2 mA.]