mirror of
https://github.com/firewalkwithm3/Sensor-Watch.git
synced 2024-11-22 19:20:30 +08:00
first steps toward supporting alternate board pinouts
This commit is contained in:
parent
5cd6b1afc7
commit
5a53916f0e
|
@ -1,28 +1,43 @@
|
|||
/*
|
||||
* Code generated from Atmel Start.
|
||||
*
|
||||
* This file will be overwritten when reconfiguring your Atmel Start project.
|
||||
* Please copy examples or other code you want to keep to a separate file
|
||||
* to avoid losing it when reconfiguring.
|
||||
*/
|
||||
#ifndef ATMEL_START_PINS_H_INCLUDED
|
||||
#define ATMEL_START_PINS_H_INCLUDED
|
||||
|
||||
#include <hal_gpio.h>
|
||||
|
||||
// SAML22 has 9 pin functions
|
||||
|
||||
#define GPIO_PIN_FUNCTION_A 0
|
||||
#define GPIO_PIN_FUNCTION_B 1
|
||||
#define GPIO_PIN_FUNCTION_C 2
|
||||
#define GPIO_PIN_FUNCTION_D 3
|
||||
#define GPIO_PIN_FUNCTION_E 4
|
||||
#define GPIO_PIN_FUNCTION_F 5
|
||||
#define GPIO_PIN_FUNCTION_G 6
|
||||
#define GPIO_PIN_FUNCTION_H 7
|
||||
#define GPIO_PIN_FUNCTION_I 8
|
||||
#ifndef PINS_H_INCLUDED
|
||||
#define PINS_H_INCLUDED
|
||||
|
||||
// Detects if we are on USB power.
|
||||
#define VBUS_DET GPIO(GPIO_PORTA, 3)
|
||||
|
||||
// Buttons
|
||||
#define BTN_ALARM GPIO(GPIO_PORTA, 2)
|
||||
#define BTN_LIGHT GPIO(GPIO_PORTA, 22)
|
||||
#define WATCH_BTN_LIGHT_EIC_PINMUX PINMUX_PA22A_EIC_EXTINT6
|
||||
#define BTN_MODE GPIO(GPIO_PORTA, 23)
|
||||
#define WATCH_BTN_MODE_EIC_PINMUX PINMUX_PA23A_EIC_EXTINT7
|
||||
|
||||
// Buzzer
|
||||
#define BUZZER GPIO(GPIO_PORTA, 27)
|
||||
#define WATCH_BUZZER_TCC_PINMUX PINMUX_PA27F_TCC0_WO5
|
||||
#define WATCH_BUZZER_TCC_CHANNEL 1
|
||||
|
||||
// LEDs
|
||||
#ifdef WATCH_SWAP_LED_PINS
|
||||
#define RED GPIO(GPIO_PORTA, 21)
|
||||
#define WATCH_RED_TCC_PINMUX PINMUX_PA21F_TCC0_WO7
|
||||
#define WATCH_RED_TCC_CHANNEL 3
|
||||
#define GREEN GPIO(GPIO_PORTA, 20)
|
||||
#define WATCH_GREEN_TCC_CHANNEL 2
|
||||
#define WATCH_GREEN_TCC_PINMUX PINMUX_PA20F_TCC0_WO6
|
||||
#else
|
||||
#define RED GPIO(GPIO_PORTA, 20)
|
||||
#define WATCH_RED_TCC_PINMUX PINMUX_PA20F_TCC0_WO6
|
||||
#define WATCH_RED_TCC_CHANNEL 2
|
||||
#define GREEN GPIO(GPIO_PORTA, 21)
|
||||
#define WATCH_GREEN_TCC_CHANNEL 3
|
||||
#define WATCH_GREEN_TCC_PINMUX PINMUX_PA21F_TCC0_WO7
|
||||
#endif
|
||||
|
||||
// Segment LCD
|
||||
#define COM0 GPIO(GPIO_PORTB, 6)
|
||||
#define COM1 GPIO(GPIO_PORTB, 7)
|
||||
#define COM2 GPIO(GPIO_PORTB, 8)
|
||||
#define SEG0 GPIO(GPIO_PORTB, 9)
|
||||
#define SEG1 GPIO(GPIO_PORTA, 4)
|
||||
#define SEG2 GPIO(GPIO_PORTA, 5)
|
||||
#define SEG3 GPIO(GPIO_PORTA, 6)
|
||||
|
@ -31,6 +46,11 @@
|
|||
#define SEG6 GPIO(GPIO_PORTA, 9)
|
||||
#define SEG7 GPIO(GPIO_PORTA, 10)
|
||||
#define SEG8 GPIO(GPIO_PORTA, 11)
|
||||
#define SEG9 GPIO(GPIO_PORTB, 11)
|
||||
#define SEG10 GPIO(GPIO_PORTB, 12)
|
||||
#define SEG11 GPIO(GPIO_PORTB, 13)
|
||||
#define SEG12 GPIO(GPIO_PORTB, 14)
|
||||
#define SEG13 GPIO(GPIO_PORTB, 15)
|
||||
#define SEG14 GPIO(GPIO_PORTA, 12)
|
||||
#define SEG15 GPIO(GPIO_PORTA, 13)
|
||||
#define SEG16 GPIO(GPIO_PORTA, 14)
|
||||
|
@ -39,36 +59,20 @@
|
|||
#define SEG19 GPIO(GPIO_PORTA, 17)
|
||||
#define SEG20 GPIO(GPIO_PORTA, 18)
|
||||
#define SEG21 GPIO(GPIO_PORTA, 19)
|
||||
#ifdef WATCH_SWAP_LED_PINS
|
||||
#define RED GPIO(GPIO_PORTA, 21)
|
||||
#define GREEN GPIO(GPIO_PORTA, 20)
|
||||
#else
|
||||
#define RED GPIO(GPIO_PORTA, 20)
|
||||
#define GREEN GPIO(GPIO_PORTA, 21)
|
||||
#endif
|
||||
#define BTN_ALARM GPIO(GPIO_PORTA, 2)
|
||||
#define BTN_LIGHT GPIO(GPIO_PORTA, 22)
|
||||
#define BTN_MODE GPIO(GPIO_PORTA, 23)
|
||||
#define BUZZER GPIO(GPIO_PORTA, 27)
|
||||
#define SEG22 GPIO(GPIO_PORTB, 16)
|
||||
#define SEG23 GPIO(GPIO_PORTB, 17)
|
||||
|
||||
// 9-pin connector
|
||||
#define A0 GPIO(GPIO_PORTB, 4)
|
||||
#define A1 GPIO(GPIO_PORTB, 1)
|
||||
#define A2 GPIO(GPIO_PORTB, 2)
|
||||
#define A3 GPIO(GPIO_PORTB, 3)
|
||||
#define A4 GPIO(GPIO_PORTB, 0)
|
||||
#define D0 GPIO(GPIO_PORTB, 3)
|
||||
#define D1 GPIO(GPIO_PORTB, 0)
|
||||
#define COM0 GPIO(GPIO_PORTB, 6)
|
||||
#define COM1 GPIO(GPIO_PORTB, 7)
|
||||
#define COM2 GPIO(GPIO_PORTB, 8)
|
||||
#define SEG0 GPIO(GPIO_PORTB, 9)
|
||||
#define SEG9 GPIO(GPIO_PORTB, 11)
|
||||
#define SEG10 GPIO(GPIO_PORTB, 12)
|
||||
#define SEG11 GPIO(GPIO_PORTB, 13)
|
||||
#define SEG12 GPIO(GPIO_PORTB, 14)
|
||||
#define SEG13 GPIO(GPIO_PORTB, 15)
|
||||
#define SEG22 GPIO(GPIO_PORTB, 16)
|
||||
#define SEG23 GPIO(GPIO_PORTB, 17)
|
||||
#define SDA GPIO(GPIO_PORTB, 30)
|
||||
#define SCL GPIO(GPIO_PORTB, 31)
|
||||
|
||||
#endif // ATMEL_START_PINS_H_INCLUDED
|
||||
// aliases for as A3/A4; these were mentioned as D0/D1 in early documentation.
|
||||
#define D0 GPIO(GPIO_PORTB, 3)
|
||||
#define D1 GPIO(GPIO_PORTB, 0)
|
||||
|
||||
#endif // PINS_H_INCLUDED
|
5
make.mk
5
make.mk
|
@ -2,6 +2,10 @@
|
|||
BUILD = ./build
|
||||
BIN = watch
|
||||
|
||||
ifndef BOARD
|
||||
override BOARD = OSO-SWAT-A1-04
|
||||
endif
|
||||
|
||||
##############################################################################
|
||||
.PHONY: all directory clean size
|
||||
|
||||
|
@ -31,6 +35,7 @@ LDFLAGS += -Wl,--script=../../watch-library/linker/saml22j18.ld
|
|||
# ../drivers/
|
||||
INCLUDES += \
|
||||
-I../../tinyusb/src \
|
||||
-I../../boards/$(BOARD) \
|
||||
-I../../watch-library/include \
|
||||
-I../../watch-library/hal/ \
|
||||
-I../../watch-library/hal/documentation/ \
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#ifndef DRIVER_INIT_INCLUDED
|
||||
#define DRIVER_INIT_INCLUDED
|
||||
|
||||
#include "atmel_start_pins.h"
|
||||
#include "pins.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#include <stdio.h>
|
||||
#include "saml22.h"
|
||||
#include "hal_init.h"
|
||||
#include "atmel_start_pins.h"
|
||||
#include "pins.h"
|
||||
#include "watch.h"
|
||||
#include "tusb.h"
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ void watch_disable_buzzer() {
|
|||
|
||||
inline void watch_set_buzzer_on() {
|
||||
gpio_set_pin_direction(BUZZER, GPIO_DIRECTION_OUT);
|
||||
gpio_set_pin_function(BUZZER, PINMUX_PA27F_TCC0_WO5);
|
||||
gpio_set_pin_function(BUZZER, WATCH_BUZZER_TCC_PINMUX);
|
||||
}
|
||||
|
||||
inline void watch_set_buzzer_off() {
|
||||
|
@ -54,7 +54,7 @@ void watch_buzzer_play_note(BuzzerNote note, uint16_t duration_ms) {
|
|||
watch_set_buzzer_off();
|
||||
} else {
|
||||
hri_tcc_write_PERBUF_reg(TCC0, NotePeriods[note]);
|
||||
hri_tcc_write_CCBUF_reg(TCC0, 1, NotePeriods[note] / 2);
|
||||
hri_tcc_write_CCBUF_reg(TCC0, WATCH_BUZZER_TCC_CHANNEL, NotePeriods[note] / 2);
|
||||
watch_set_buzzer_on();
|
||||
}
|
||||
delay_ms(duration_ms);
|
||||
|
|
|
@ -77,13 +77,13 @@ void watch_register_interrupt_callback(const uint8_t pin, ext_irq_cb_t callback,
|
|||
break;
|
||||
case BTN_LIGHT:
|
||||
gpio_set_pin_pull_mode(pin, GPIO_PULL_DOWN);
|
||||
pinmux = PINMUX_PA22A_EIC_EXTINT6;
|
||||
pinmux = WATCH_BTN_LIGHT_EIC_PINMUX;
|
||||
config &= ~EIC_CONFIG_SENSE6_Msk;
|
||||
config |= EIC_CONFIG_SENSE6(trigger);
|
||||
break;
|
||||
case BTN_MODE:
|
||||
gpio_set_pin_pull_mode(pin, GPIO_PULL_DOWN);
|
||||
pinmux = PINMUX_PA23A_EIC_EXTINT7;
|
||||
pinmux = WATCH_BTN_MODE_EIC_PINMUX;
|
||||
config &= ~EIC_CONFIG_SENSE7_Msk;
|
||||
config |= EIC_CONFIG_SENSE7(trigger);
|
||||
break;
|
||||
|
|
|
@ -22,14 +22,6 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifdef WATCH_SWAP_LED_PINS
|
||||
#define WATCH_RED_CHANNEL 3
|
||||
#define WATCH_GREEN_CHANNEL 2
|
||||
#else
|
||||
#define WATCH_RED_CHANNEL 2
|
||||
#define WATCH_GREEN_CHANNEL 3
|
||||
#endif
|
||||
|
||||
void watch_enable_leds() {
|
||||
if (!hri_tcc_get_CTRLA_reg(TCC0, TCC_CTRLA_ENABLE)) {
|
||||
_watch_enable_tcc();
|
||||
|
@ -53,8 +45,8 @@ void watch_disable_led(bool unused) {
|
|||
void watch_set_led_color(uint8_t red, uint8_t green) {
|
||||
if (hri_tcc_get_CTRLA_reg(TCC0, TCC_CTRLA_ENABLE)) {
|
||||
uint32_t period = hri_tcc_get_PER_reg(TCC0, TCC_PER_MASK);
|
||||
hri_tcc_write_CCBUF_reg(TCC0, WATCH_RED_CHANNEL, ((period * red * 1000ull) / 255000ull));
|
||||
hri_tcc_write_CCBUF_reg(TCC0, WATCH_GREEN_CHANNEL, ((period * green * 1000ull) / 255000ull));
|
||||
hri_tcc_write_CCBUF_reg(TCC0, WATCH_RED_TCC_CHANNEL, ((period * red * 1000ull) / 255000ull));
|
||||
hri_tcc_write_CCBUF_reg(TCC0, WATCH_GREEN_TCC_CHANNEL, ((period * green * 1000ull) / 255000ull));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -93,18 +93,18 @@ void _watch_enable_tcc() {
|
|||
// get the LED working. Almost any period will do, tho it should be below 20000 (i.e. 50 Hz) to avoid flickering.
|
||||
hri_tcc_write_PER_reg(TCC0, 4096);
|
||||
// Set the duty cycle of all pins to 0: LED's off, buzzer not buzzing.
|
||||
hri_tcc_write_CC_reg(TCC0, 1, 0);
|
||||
hri_tcc_write_CC_reg(TCC0, 2, 0);
|
||||
hri_tcc_write_CC_reg(TCC0, 3, 0);
|
||||
hri_tcc_write_CC_reg(TCC0, WATCH_BUZZER_TCC_CHANNEL, 0);
|
||||
hri_tcc_write_CC_reg(TCC0, WATCH_RED_TCC_CHANNEL, 0);
|
||||
hri_tcc_write_CC_reg(TCC0, WATCH_GREEN_TCC_CHANNEL, 0);
|
||||
// Enable the TCC
|
||||
hri_tcc_set_CTRLA_ENABLE_bit(TCC0);
|
||||
hri_tcc_wait_for_sync(TCC0, TCC_SYNCBUSY_ENABLE);
|
||||
|
||||
// enable LED PWM pins (the LED driver assumes if the TCC is on, the pins are enabled)
|
||||
gpio_set_pin_direction(RED, GPIO_DIRECTION_OUT);
|
||||
gpio_set_pin_function(RED, PINMUX_PA20F_TCC0_WO6);
|
||||
gpio_set_pin_function(RED, WATCH_RED_TCC_PINMUX);
|
||||
gpio_set_pin_direction(GREEN, GPIO_DIRECTION_OUT);
|
||||
gpio_set_pin_function(GREEN, PINMUX_PA21F_TCC0_WO7);
|
||||
gpio_set_pin_function(GREEN, WATCH_GREEN_TCC_PINMUX);
|
||||
}
|
||||
|
||||
void _watch_disable_tcc() {
|
||||
|
|
Loading…
Reference in a new issue