prepared bootloader for use with Sun Type 5 keyboard
This commit is contained in:
		| @@ -22,7 +22,9 @@ AVRDUDE = avrdude $(PROGRAMMER) -p $(DEVICE) | ||||
| CC = avr-gcc | ||||
|  | ||||
| # Options: | ||||
| DEFINES = #-DDEBUG_LEVEL=2 | ||||
| DEFINES = -DMODELIBMMODELM | ||||
| #DEFINES = -DMODELSUNTYPE5 | ||||
|  | ||||
| CFLAGS = -Wall -Os -I. -mmcu=$(DEVICE) -DF_CPU=$(F_CPU) $(DEFINES) | ||||
| LDFLAGS = -Wl,--section-start=.text=$(BOOTLOADER_ADDRESS) | ||||
|  | ||||
|   | ||||
| @@ -115,6 +115,15 @@ | ||||
|  | ||||
| #ifndef __ASSEMBLER__   /* assembler cannot parse function definitions */ | ||||
|  | ||||
| #ifdef MODELSUNTYPE5 | ||||
| #   define SRCLOCKON    PORTC |= (1 << PC5) | ||||
| #   define SRCLOCKOFF   PORTC &= ~(1 << PC5) | ||||
| #   define SRDATAON     PORTC |= (1 << PC6) | ||||
| #   define SRDATAOFF    PORTC &= ~(1 << PC6) | ||||
| #   define SRSTROBEON   PORTC |= (1 << PC7) | ||||
| #   define SRSTROBEOFF  PORTC &= ~(1 << PC7) | ||||
| #   define KEYROW 6 | ||||
| #endif | ||||
| uint8_t ledcounter = 0; ///< counter used to set the speed of the running light | ||||
| uint8_t ledstate = 0;   ///< state of the running light | ||||
|  | ||||
| @@ -122,25 +131,67 @@ uint8_t ledstate = 0;   ///< state of the running light | ||||
|  * Prepare IO-ports for detection of bootloader-condition, which happens in | ||||
|  * bootLoaderCondition(). | ||||
|  */ | ||||
| #ifdef MODELIBMMODELM | ||||
| static inline void bootLoaderInit(void) { | ||||
|     // switch on leds | ||||
|     DDRD  |= (1 << PIND4) | (1 << PIND5) | (1 << PIND6); | ||||
|     PORTD &= ~((1 << PIND4) | (1 << PIND5) | (1 << PIND6)); | ||||
|     // choose matrix position for hotkey. we use KEY_KPminus, so we set row 13 | ||||
|     // and later look for pin 7 | ||||
|     // and later look for column 7 | ||||
|     DDRA  = 0x00; | ||||
|     PORTA = 0xff; | ||||
|     DDRC  = (1 << DDC2); | ||||
|     PORTC = ~(1 << PINC2); | ||||
| } | ||||
| #endif | ||||
| #ifdef MODELSUNTYPE5 | ||||
| static inline void bootLoaderInit(void) { | ||||
|     // configure ports | ||||
|     DDRA = 0x00; | ||||
|     PORTA = 0xff; | ||||
|     DDRB = (1 << PB4) |(1 << PB5) | (1 << PB6) | (1 << PB7); | ||||
|     PORTB = (1 << PB0) | (1 << PB1) | (1 << PB2) | (1 << PB3); | ||||
|     DDRC = (1 << PC5) | (1 << PC6) | (1 << PC7); | ||||
|     PORTC = (1 << PC0) | (1 << PC1) | (1 << PC2) | (1 << PC3) | (1 << PC4); | ||||
|     DDRD &= ~((1 << PD4) | (1 << PD5) | (1 << PD6) | (1 << PD7)); | ||||
|     PORTD |= (1 << PD4) | (1 << PD5) | (1 << PD6) | (1 << PD7); | ||||
|  | ||||
|     // switch on leds | ||||
|     PORTB &= ~((1 << PB4) | (1 << PB5) | (1 << PB6) | (1 << PB7)); | ||||
|  | ||||
|     // choose matrix position for hotkey. we use KEY_KPminus, so we set all | ||||
|     // rows to 1 except for row 6 (KEYROW) and later look for column 6 | ||||
|     SRDATAON; | ||||
|     SRSTROBEOFF; | ||||
|     uint8_t i = 0; | ||||
|     for (i = 0; i < (21 - KEYROW); i++) { | ||||
|         SRCLOCKON; SRCLOCKOFF; | ||||
|     } | ||||
|     SRDATAOFF; | ||||
|     SRCLOCKON; SRCLOCKOFF; | ||||
|     SRDATAON; | ||||
|     for (i = 0; i < KEYROW; i++) { | ||||
|         SRCLOCKON; SRCLOCKOFF; | ||||
|     } | ||||
|     SRSTROBEON; SRSTROBEOFF; | ||||
| } | ||||
| #endif | ||||
|  | ||||
| /** | ||||
|  * Clean up after boot loader action. In this case: switch off all LEDs. | ||||
|  */ | ||||
| #ifdef MODELIBMMODELM | ||||
| static inline void bootLoaderExit(void) { | ||||
|     // switch off leds | ||||
|     PORTD |= (1 << PIND4) | (1 << PIND5) | (1 << PIND6); | ||||
| } | ||||
| #endif | ||||
| #ifdef MODELSUNTYPE5 | ||||
| static inline void bootLoaderExit(void) { | ||||
|     // switch off leds | ||||
|     PORTB |= (1 << PB4) | (1 << PB5) | (1 << PB6) | (1 << PB7); | ||||
| } | ||||
| #endif | ||||
|  | ||||
| /** | ||||
|  * Check if conditions for boot loader are met. This function is called in an | ||||
| @@ -148,6 +199,7 @@ static inline void bootLoaderExit(void) { | ||||
|  * the LEDs. | ||||
|  * \return 1 if bootloader should be active, 0 otherwise | ||||
|  */ | ||||
| #ifdef MODELIBMMODELM | ||||
| static inline uint8_t bootLoaderCondition() { | ||||
|     // look for pin 7 | ||||
|     if (!(PINB & (1 << PINB7))) { | ||||
| @@ -182,6 +234,48 @@ static inline uint8_t bootLoaderCondition() { | ||||
|         return 0; | ||||
|     } | ||||
| } | ||||
| #endif | ||||
| #ifdef MODELSUNTYPE5 | ||||
| static inline uint8_t bootLoaderCondition() { | ||||
|     // look for pin 7 | ||||
|     if (!(PINA & (1 << PINA6))) { | ||||
|         // boot loader active, blink leds | ||||
|         _delay_ms(1); | ||||
|         ledcounter++; | ||||
|         if (ledcounter == 127) { | ||||
|             switch (ledstate) { | ||||
|                 case 0: | ||||
|                     PORTB &= ~(1 << PINB7); | ||||
|                     PORTB |= (1 << PINB4) | (1 << PINB5) | (1 << PINB6); | ||||
|                     ledstate = 1; | ||||
|                     break; | ||||
|                 case 1: | ||||
|                     PORTB &= ~(1 << PINB6); | ||||
|                     PORTB |= (1 << PINB4) | (1 << PINB5) | (1 << PINB7); | ||||
|                     ledstate = 2; | ||||
|                     break; | ||||
|                 case 2: | ||||
|                     PORTB &= ~(1 << PINB5); | ||||
|                     PORTB |= (1 << PINB4) | (1 << PINB6) | (1 << PINB7); | ||||
|                     ledstate = 3; | ||||
|                     break; | ||||
|                 case 3: | ||||
|                     PORTB &= ~(1 << PINB4); | ||||
|                     PORTB |= (1 << PINB5) | (1 << PINB6) | (1 << PINB7); | ||||
|                     ledstate = 0; | ||||
|                     break; | ||||
|                 default: | ||||
|                     ledstate = 0; | ||||
|             } | ||||
|             ledcounter = 0; | ||||
|         } | ||||
|         return 1; | ||||
|     } else { | ||||
|         // no boot loader | ||||
|         return 0; | ||||
|     } | ||||
| } | ||||
| #endif | ||||
|  | ||||
| #endif /* __ASSEMBLER__ */ | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user