summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/arch.h2
-rw-r--r--include/arch/msp430fr5969lp/driver/gpio.h5
-rw-r--r--include/arch/msp430fr5994lp/driver/timed_resistive_load.h72
-rw-r--r--include/driver/mmsubstate.h24
4 files changed, 103 insertions, 0 deletions
diff --git a/include/arch.h b/include/arch.h
index 877af62..1911271 100644
--- a/include/arch.h
+++ b/include/arch.h
@@ -10,6 +10,8 @@ class Arch {
void setup();
void idle_loop();
void idle();
+
+ // Delay functions are not exact
void delay_us(unsigned int const us);
void delay_ms(unsigned int const ms);
void sleep_ms(unsigned int const ms);
diff --git a/include/arch/msp430fr5969lp/driver/gpio.h b/include/arch/msp430fr5969lp/driver/gpio.h
index d279e31..65b5567 100644
--- a/include/arch/msp430fr5969lp/driver/gpio.h
+++ b/include/arch/msp430fr5969lp/driver/gpio.h
@@ -66,14 +66,19 @@ class GPIO {
inline void input(unsigned char const pin) {
if (pin < p2_0) {
P1DIR &= ~(1 << pin);
+ P1REN &= ~(1 << pin);
} else if (pin < p3_0) {
P2DIR &= ~(1 << (pin - p2_0));
+ P2REN &= ~(1 << (pin - p2_0));
} else if (pin < p4_0) {
P3DIR &= ~(1 << (pin - p3_0));
+ P3REN &= ~(1 << (pin - p3_0));
} else if (pin < pj_0) {
P4DIR &= ~(1 << (pin - p4_0));
+ P4REN &= ~(1 << (pin - p4_0));
} else if (pin < PIN_INVALID) {
PJDIR &= ~(1 << (pin - pj_0));
+ PJREN &= ~(1 << (pin - pj_0));
}
}
inline void input(unsigned char const pin, unsigned char const pull) {
diff --git a/include/arch/msp430fr5994lp/driver/timed_resistive_load.h b/include/arch/msp430fr5994lp/driver/timed_resistive_load.h
new file mode 100644
index 0000000..6e7996c
--- /dev/null
+++ b/include/arch/msp430fr5994lp/driver/timed_resistive_load.h
@@ -0,0 +1,72 @@
+#ifndef TIMED_RESISTIVE_LOAD_H
+#define TIMED_RESISTIVE_LOAD_H
+
+/*
+ * Resistance at 25°c
+ * R1: 986R
+ * R2: 3K25
+ * R3: 46K3
+ * R4: 9K86
+ */
+
+class TimedResistiveLoad {
+ private:
+ TimedResistiveLoad(const TimedResistiveLoad &copy);
+
+ public:
+ TimedResistiveLoad() {}
+ void setup();
+ void switchToNone();
+ void switchTo750(); // 576R (R1 || R2)
+ void switchTo1K0(); // 986R (R1)
+ void switchTo2K4(); // 2K44 (R2 || 4)
+ void switchTo3K3(); // 3K25 (R2)
+ void switchTo10K(); // 9K86 (R4)
+ void switchTo47K(); // 46K3 (R3)
+
+ /*
+ * These functions must be inline, as __delay_cycles only works with
+ * compile-time constants. So they must be part of the compilation unit
+ * which uses them and cannot easily be wrapped by a function without
+ * losing accuracy.
+ */
+
+ inline void __attribute__((always_inline)) nop1K0(unsigned long long int const duration_us)
+ {
+ switchTo1K0();
+ __delay_cycles(F_CPU / 1000000UL * duration_us);
+ switchToNone();
+ }
+
+ inline void __attribute__((always_inline)) nop2K4(unsigned long long int const duration_us)
+ {
+ switchTo2K4();
+ __delay_cycles(F_CPU / 1000000UL * duration_us);
+ switchToNone();
+ }
+
+ inline void __attribute__((always_inline)) nop3K3(unsigned long long int const duration_us)
+ {
+ switchTo3K3();
+ __delay_cycles(F_CPU / 1000000UL * duration_us);
+ switchToNone();
+ }
+
+ inline void __attribute__((always_inline)) nop10K(unsigned long long int const duration_us)
+ {
+ switchTo10K();
+ __delay_cycles(F_CPU / 1000000UL * duration_us);
+ switchToNone();
+ }
+
+ inline void __attribute__((always_inline)) nop47K(unsigned long long int const duration_us)
+ {
+ switchTo47K();
+ __delay_cycles(F_CPU / 1000000UL * duration_us);
+ switchToNone();
+ }
+};
+
+extern TimedResistiveLoad timedResistiveLoad;
+
+#endif
diff --git a/include/driver/mmsubstate.h b/include/driver/mmsubstate.h
new file mode 100644
index 0000000..3338dbc
--- /dev/null
+++ b/include/driver/mmsubstate.h
@@ -0,0 +1,24 @@
+#ifndef MMSUBSTATE_H
+#define MMSUBSTATE_H
+
+class MicroMoodySubstate {
+ private:
+ MicroMoodySubstate(const MicroMoodySubstate &copy);
+
+ unsigned char const address;
+ unsigned char txbuf[3];
+
+ public:
+ MicroMoodySubstate(unsigned char const addr) : address(addr) {}
+
+ void sleep();
+ void noSubstates(unsigned char power1, unsigned char power2);
+ void twoSubstates(unsigned char switchDutarion, unsigned char power);
+ void fourSubstates(unsigned char switchDutarion, unsigned char power);
+ void eightSubstates(unsigned char switchDutarion, unsigned char power);
+ void setSubstates(unsigned char substateCount, unsigned char switchDuration, unsigned char power);
+};
+
+extern MicroMoodySubstate moody;
+
+#endif