diff options
author | Lennart <lekaiser@uos.de> | 2020-07-25 20:50:23 +0200 |
---|---|---|
committer | Lennart <lekaiser@uos.de> | 2020-07-25 20:50:23 +0200 |
commit | 714e5788be7b89f937fe8dbf270b8035c4f7d436 (patch) | |
tree | e05ae1a2b421840847ae28d053a26d8538fe89c1 /include/arch | |
parent | 5c4045862bf55be0b8dc755ac3d5c5bd24b5fedf (diff) | |
parent | d0ea0a521a582549dfd9a98b47e7c12d8bcd0de6 (diff) |
Merge branch 'master' into state-duration-timers
Diffstat (limited to 'include/arch')
-rw-r--r-- | include/arch/msp430fr5969lp/driver/gpio.h | 5 | ||||
-rw-r--r-- | include/arch/msp430fr5994lp/driver/timed_resistive_load.h | 72 |
2 files changed, 77 insertions, 0 deletions
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 ©); + + 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 |