/      日本語

PAL Common Definitions

Common definitions for the TWELITE PAL series
TWELITE PAL hardware shares common components, and board behaviors define a shared interface for those components.

Constants

The following constants are defined:

static const uint8_t PIN_BTN = 12; // button (as SET)
static const uint8_t PIN_LED = 5;  // LED
static const uint8_t PIN_WDT = 13; // WDT (shall tick every 60sec)

static const uint8_t PIN_D1 = 1; // DIP SW1
static const uint8_t PIN_D2 = 2; // DIP SW2
static const uint8_t PIN_D3 = 3; // DIP SW3
static const uint8_t PIN_D4 = 4; // DIP SW4

static const uint8_t PIN_SNS_EN = 16;
static const uint8_t PIN_SNS_INT = 17;

These can be accessed like PAL_AMB::PIN_BTN.

Hardware Initialization

pinMode(PIN_BTN, INPUT_PULLUP);
pinMode(PIN_LED, OUTPUT_INIT_HIGH);
pinMode(PIN_WDT, OUTPUT_INIT_HIGH);

pinMode(PIN_D1, INPUT_PULLUP);
pinMode(PIN_D2, INPUT_PULLUP);
pinMode(PIN_D3, INPUT_PULLUP);
pinMode(PIN_D4, INPUT_PULLUP);

Pins are initialized as shown in the code above.

Watchdog Timer

The external watchdog timer is reset at startup, after waking from sleep, and after a certain amount of time has passed since startup.

Methods

set_led()

void set_led(uint8_t mode, uint16_t tick)

Controls LED (D1).

mode takes the following parameters. tick specifies the ON duration [ms], but see the explanation of mode for details.

ModeDescription
LED_TIMER::BLINKBlinks the LED. Toggles ON/OFF every tick ms. After waking from sleep, it resets and starts ON.
LED_TIMER::ON_RXTurns on the LED for tick ms when a packet is received.
LED_TIMER::ON_TX_COMPTurns on the LED for tick ms when transmission completes.

led_one_shot()

void led_one_shot(uint16_t tick)

Turns on the LED for a specified duration. Cannot be used simultaneously with set_led().

get_D1() .. D4(), get_DIPSW_BM()

inline uint8_t get_D1()
inline uint8_t get_D2()
inline uint8_t get_D3()
inline uint8_t get_D4()
inline uint8_t get_DIPSW_BM()

get_D1() through get_D4() return 0 when the DIP switch is in the HIGH (up) position, and 1 when in the LOW (down) position.

get_DIPSW_BM() returns the DIP switch setting as a value from 0 to 15, calculated as: SW1==LOW = 1, SW2==LOW = 2, SW3==LOW = 4, and SW4==LOW = 8.


<PAL_NOTICE>

For NOTICE PAL

<PAL_AMB>

For Ambient Sensor PAL

<PAL_MAG>

For Open-Close Sensor PAL

<PAL_MOT>

For Motion Sensor PAL