aboutsummaryrefslogtreecommitdiffstats
path: root/sw/pins.h
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2019-10-26 23:29:22 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2019-10-26 23:29:22 +0200
commit66cdf851a8e945adf702088d9f78f850c8b8932c (patch)
treebbeb6b4f30bfc08e2064a375c27fae4f88411559 /sw/pins.h
parentf6c2c762afc1d527cf40f8925ecf22b8b5845b43 (diff)
downloadglutte-batteries-66cdf851a8e945adf702088d9f78f850c8b8932c.tar.gz
glutte-batteries-66cdf851a8e945adf702088d9f78f850c8b8932c.tar.bz2
glutte-batteries-66cdf851a8e945adf702088d9f78f850c8b8932c.zip
Add preliminary mAh accumulator
Diffstat (limited to 'sw/pins.h')
-rw-r--r--sw/pins.h54
1 files changed, 37 insertions, 17 deletions
diff --git a/sw/pins.h b/sw/pins.h
index 6dc75bc..c69870d 100644
--- a/sw/pins.h
+++ b/sw/pins.h
@@ -26,9 +26,10 @@
#include <stdlib.h>
#include <stdint.h>
+#include <avr/io.h>
+#include <avr/interrupt.h>
// Definitions allocation pin
-#define PIN(x) (1 << x)
/* All relay signals PINx_Kx have external pulldown.
* All pins whose name ends in 'n' are active low */
@@ -37,38 +38,57 @@
// lib/pins_arduino.h
// PORT B
-constexpr uint8_t PINB_STATUSn = PIN(0);
+constexpr uint8_t PINB_STATUSn = _BV(0);
// Pins 2,3,4,5 = SPI
-constexpr uint8_t PINB_SPI_LTC_CSn = PIN(2); // with external pullup
-constexpr uint8_t PINB_SPI_MOSI = PIN(3);
-constexpr uint8_t PINB_SPI_MISO = PIN(4);
-constexpr uint8_t PINB_SPI_SCK = PIN(5);
+constexpr uint8_t PINB_SPI_LTC_CSn = _BV(2); // with external pullup
+constexpr uint8_t PINB_SPI_MOSI = _BV(3);
+constexpr uint8_t PINB_SPI_MISO = _BV(4);
+constexpr uint8_t PINB_SPI_SCK = _BV(5);
constexpr uint8_t PINB_OUTPUTS =
PINB_STATUSn | PINB_SPI_SCK | PINB_SPI_MOSI | PINB_SPI_LTC_CSn;
+constexpr uint8_t PINB_INIT =
+ PINB_STATUSn | PINB_SPI_LTC_CSn;
+
// PORT C
-constexpr uint8_t PINC_ADC0 = PIN(0);
-constexpr uint8_t PINC_ADC1 = PIN(1);
-constexpr uint8_t PINC_K3_RESET = PIN(2);
-constexpr uint8_t PINC_K3_SET = PIN(3);
-constexpr uint8_t PINC_K2_RESET = PIN(4);
-constexpr uint8_t PINC_K2_SET = PIN(5);
+constexpr uint8_t PINC_ADC0 = _BV(0);
+constexpr uint8_t PINC_ADC1 = _BV(1);
+constexpr uint8_t PINC_K3_RESET = _BV(2);
+constexpr uint8_t PINC_K3_SET = _BV(3);
+constexpr uint8_t PINC_K2_RESET = _BV(4);
+constexpr uint8_t PINC_K2_SET = _BV(5);
constexpr uint8_t PINC_OUTPUTS =
PINC_K3_RESET | PINC_K3_SET |
PINC_K2_RESET | PINC_K2_SET;
+constexpr uint8_t PINC_INIT = 0;
+
// PORT D
// Pins 0,1 = UART RX,TX
-constexpr uint8_t PIND_UART_RX = PIN(0);
-constexpr uint8_t PIND_UART_TX = PIN(1);
+constexpr uint8_t PIND_UART_RX = _BV(0);
+constexpr uint8_t PIND_UART_TX = _BV(1);
-constexpr uint8_t PIND_ONEWIRE = PIN(4); // with exteral pullup
+constexpr uint8_t PIND_ONEWIRE = _BV(4); // with exteral pullup
-constexpr uint8_t PIND_K1_RESET = PIN(5);
-constexpr uint8_t PIND_K1_SET = PIN(6);
+constexpr uint8_t PIND_K1_RESET = _BV(5);
+constexpr uint8_t PIND_K1_SET = _BV(6);
constexpr uint8_t PIND_OUTPUTS =
PIND_UART_TX |
PIND_K1_RESET | PIND_K1_SET;
+
+constexpr uint8_t PIND_INIT = 0;
+
+inline void pins_set_status(bool enable)
+{
+ cli();
+ if (enable) {
+ PORTB &= ~PINB_STATUSn;
+ }
+ else {
+ PORTB |= PINB_STATUSn;
+ }
+ sei();
+}