little work on the teensy init function and header; not much else
parent
a288b8a045
commit
f49d503698
|
@ -1,5 +1,5 @@
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
* Firmware main file
|
* main()
|
||||||
* ----------------------------------------------------------------------------
|
* ----------------------------------------------------------------------------
|
||||||
* Copyright (c) 2012 Ben Blazak <benblazak.dev@gmail.com>
|
* Copyright (c) 2012 Ben Blazak <benblazak.dev@gmail.com>
|
||||||
* Released under The MIT License (MIT) (see "license.md")
|
* Released under The MIT License (MIT) (see "license.md")
|
||||||
|
|
|
@ -15,8 +15,7 @@
|
||||||
#define KB_ROWS 12 // must match real life
|
#define KB_ROWS 12 // must match real life
|
||||||
#define KB_COLUMNS 7 // must match real life
|
#define KB_COLUMNS 7 // must match real life
|
||||||
|
|
||||||
extern bool kb_is_pressed[KB_ROWS][KB_COLUMNS];
|
extern bool kb_is_pressed[KB_ROWS][KB_COLUMNS] = {};
|
||||||
bool kb_is_pressed[KB_ROWS][KB_COLUMNS];
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ uint8_t teensy_init(void) {
|
||||||
DDRB &= ~0b00001110; // set B(3,2,1) as input
|
DDRB &= ~0b00001110; // set B(3,2,1) as input
|
||||||
PORTB |= 0b00001110; // set B(3,2,1) internal pull-up enabled
|
PORTB |= 0b00001110; // set B(3,2,1) internal pull-up enabled
|
||||||
DDRD &= ~0b01110000; // set D(6,5,4) as input
|
DDRD &= ~0b01110000; // set D(6,5,4) as input
|
||||||
PORTD |= 0b01110000; // set D(6,5,4) internal pull-up enabled
|
PORTD |= 0b00110000; // set D( 5,4) internal pull-up enabled
|
||||||
DDRE &= ~0b01000000; // set E(6) as input
|
DDRE &= ~0b01000000; // set E(6) as input
|
||||||
PORTE |= 0b01000000; // set E(6) internal pull-up enabled
|
PORTE |= 0b01000000; // set E(6) internal pull-up enabled
|
||||||
|
|
||||||
|
|
|
@ -13,16 +13,16 @@
|
||||||
#include <avr/io.h> // for the register macros
|
#include <avr/io.h> // for the register macros
|
||||||
|
|
||||||
// LED control
|
// LED control
|
||||||
#define KB_LED1_ON (OCR1A = 0xFF)
|
#define KB_LED1_ON (DDRB |= (1<<5))
|
||||||
#define KB_LED1_OFF (OCR1A = 0x00)
|
#define KB_LED1_OFF (DDRB &= ~(1<<5))
|
||||||
#define KB_LED1_SET(n) (OCR1A = (uint8_t)(n))
|
#define KB_LED1_SET(n) (OCR1A = (uint8_t)(n))
|
||||||
#define KB_LED1_SET_PERCENT(n) (OCR1A = (uint8_t)((n) * 0xFF))
|
#define KB_LED1_SET_PERCENT(n) (OCR1A = (uint8_t)((n) * 0xFF))
|
||||||
#define KB_LED2_ON (OCR1B = 0xFF)
|
#define KB_LED2_ON (DDRB |= (1<<6))
|
||||||
#define KB_LED2_OFF (OCR1B = 0x00)
|
#define KB_LED2_OFF (DDRB &= ~(1<<6))
|
||||||
#define KB_LED2_SET(n) (OCR1B = (uint8_t)(n))
|
#define KB_LED2_SET(n) (OCR1B = (uint8_t)(n))
|
||||||
#define KB_LED2_SET_PERCENT(n) (OCR1B = (uint8_t)((n) * 0xFF))
|
#define KB_LED2_SET_PERCENT(n) (OCR1B = (uint8_t)((n) * 0xFF))
|
||||||
#define KB_LED3_ON (OCR1C = 0xFF)
|
#define KB_LED3_ON (DDRB |= (1<<7))
|
||||||
#define KB_LED3_OFF (OCR1C = 0x00)
|
#define KB_LED3_OFF (DDRB &= ~(1<<7))
|
||||||
#define KB_LED3_SET(n) (OCR1C = (uint8_t)(n))
|
#define KB_LED3_SET(n) (OCR1C = (uint8_t)(n))
|
||||||
#define KB_LED3_SET_PERCENT(n) (OCR1C = (uint8_t)((n) * 0xFF))
|
#define KB_LED3_SET_PERCENT(n) (OCR1C = (uint8_t)((n) * 0xFF))
|
||||||
|
|
||||||
|
|
|
@ -43,8 +43,7 @@
|
||||||
* notes:
|
* notes:
|
||||||
* SCL and SDA: Need external pull-up resistors. Sometimes the Teensy
|
* SCL and SDA: Need external pull-up resistors. Sometimes the Teensy
|
||||||
internal pull-ups are enough (see datasheet section 20.5.1), but i think
|
internal pull-ups are enough (see datasheet section 20.5.1), but i think
|
||||||
for this project we'll want external ones, in case people want to separate
|
for this project we'll want external ones.
|
||||||
the halves very far.
|
|
||||||
|
|
||||||
## Notes about Registers
|
## Notes about Registers
|
||||||
|
|
||||||
|
@ -62,14 +61,17 @@
|
||||||
|
|
||||||
* notes:
|
* notes:
|
||||||
* Unused pins should be set as input with internal pullup enabled (see
|
* Unused pins should be set as input with internal pullup enabled (see
|
||||||
datasheet section 10.2.6).
|
datasheet section 10.2.6) in order to give them a defined level.
|
||||||
|
* PD6 already has a defined level (low) since it's hooked up to the onboard
|
||||||
|
LED, so there's no reason to set internal pull-up enabled on it. If we
|
||||||
|
do, it will source current to the LED, which is fine, but unnecessary.
|
||||||
* We want the row pins 'drive high' initially, and the column pins set as
|
* We want the row pins 'drive high' initially, and the column pins set as
|
||||||
input with internal pull-up. We'll cycle through driving the row pins low,
|
input with internal pull-up. We'll cycle through driving the row pins low,
|
||||||
and checking the column pins in the update function.
|
and checking the column pins in the update function.
|
||||||
|
|
||||||
### PWM on ports OC1(A|B|C) (see datasheet section 14.10)
|
### PWM on ports OC1(A|B|C) (see datasheet section 14.10)
|
||||||
|
|
||||||
* notes:
|
* notes: settings:
|
||||||
* PWM pins should be set as outputs.
|
* PWM pins should be set as outputs.
|
||||||
* we want Waveform Generation Mode 5
|
* we want Waveform Generation Mode 5
|
||||||
(fast PWM, 8-bit)
|
(fast PWM, 8-bit)
|
||||||
|
@ -88,6 +90,13 @@
|
||||||
* LEDs will be at minimum brightness until OCR1(A|B|C) are changed (since
|
* LEDs will be at minimum brightness until OCR1(A|B|C) are changed (since
|
||||||
the default value of all the bits in those registers is 0)
|
the default value of all the bits in those registers is 0)
|
||||||
|
|
||||||
|
* notes: behavior:
|
||||||
|
* The pins source current when on, and sink current when off. They aren't
|
||||||
|
set to high impediance for either.
|
||||||
|
* In Fast PWM mode setting `OCR1(A|B|C)` to `0` does not make the output on
|
||||||
|
`OC1(A|B|C)` constant low; just close. Per the datasheet, this isn't true
|
||||||
|
for every PWM mode.
|
||||||
|
|
||||||
* abbreviations:
|
* abbreviations:
|
||||||
* OCR = Output Compare Register
|
* OCR = Output Compare Register
|
||||||
* TCCR = Timer/Counter Control Register
|
* TCCR = Timer/Counter Control Register
|
||||||
|
|
53
src/test.c
53
src/test.c
|
@ -4,9 +4,12 @@
|
||||||
#include "lib-other/pjrc/blinky/print.h"
|
#include "lib-other/pjrc/blinky/print.h"
|
||||||
#include "lib-other/pjrc/blinky/usb_debug_only.h"
|
#include "lib-other/pjrc/blinky/usb_debug_only.h"
|
||||||
|
|
||||||
|
#include "lib/data-types.h"
|
||||||
|
|
||||||
#define TEENSY_2_0_h_INCLUDE_PRIVATE
|
#define TEENSY_2_0_h_INCLUDE_PRIVATE
|
||||||
#include "keyboard/ergodox/teensy-2-0.h"
|
#include "keyboard/ergodox/teensy-2-0.h"
|
||||||
|
|
||||||
|
int blink_leds(void);
|
||||||
int test_i2c(void);
|
int test_i2c(void);
|
||||||
int test_kb_teensy(void);
|
int test_kb_teensy(void);
|
||||||
int main(void);
|
int main(void);
|
||||||
|
@ -14,6 +17,14 @@ int main(void);
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
|
teensy_init();
|
||||||
|
|
||||||
|
KB_LED1_SET_PERCENT(.03);
|
||||||
|
KB_LED2_SET_PERCENT(.03);
|
||||||
|
KB_LED3_SET_PERCENT(.03);
|
||||||
|
|
||||||
|
// blink_leds();
|
||||||
|
// print("--------------");
|
||||||
test_i2c();
|
test_i2c();
|
||||||
print("--------------");
|
print("--------------");
|
||||||
test_kb_teensy();
|
test_kb_teensy();
|
||||||
|
@ -21,6 +32,48 @@ int main(void) {
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
int blink_leds(void) {
|
||||||
|
for (uint8_t i=0; i<3; i++) {
|
||||||
|
KB_LED1_SET(0x10);
|
||||||
|
KB_LED2_SET(0x20);
|
||||||
|
KB_LED3_SET(0xFF);
|
||||||
|
_delay_ms(500);
|
||||||
|
KB_LED1_SET(0x20);
|
||||||
|
KB_LED2_SET(0xFF);
|
||||||
|
KB_LED3_SET(0x10);
|
||||||
|
_delay_ms(500);
|
||||||
|
KB_LED1_SET(0xFF);
|
||||||
|
KB_LED2_SET(0x10);
|
||||||
|
KB_LED3_SET(0x20);
|
||||||
|
_delay_ms(500);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (uint8_t i=0; i<2; i++) {
|
||||||
|
KB_LED1_OFF;
|
||||||
|
KB_LED2_OFF;
|
||||||
|
KB_LED3_OFF;
|
||||||
|
_delay_ms(500);
|
||||||
|
KB_LED1_ON;
|
||||||
|
KB_LED2_ON;
|
||||||
|
KB_LED3_ON;
|
||||||
|
_delay_ms(500);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool counting_up = true;
|
||||||
|
for (uint8_t i=0;;) {
|
||||||
|
(counting_up) ? i++ : i--;
|
||||||
|
if (i == 0xFF)
|
||||||
|
counting_up = false;
|
||||||
|
else if (i == 0)
|
||||||
|
counting_up = true;
|
||||||
|
|
||||||
|
KB_LED1_SET(i/2);
|
||||||
|
KB_LED2_SET(i/2);
|
||||||
|
KB_LED3_SET(i/2);
|
||||||
|
_delay_ms(10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int test_i2c(void) {
|
int test_i2c(void) {
|
||||||
usb_init();
|
usb_init();
|
||||||
_delay_ms(500); // just to be safe
|
_delay_ms(500); // just to be safe
|
||||||
|
|
Loading…
Reference in New Issue