Morse Micro IoT SDK  2.9.7
mmhal.h
1/*
2 * Copyright 2021-2023 Morse Micro
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7
16#pragma once
17
18#include <stdbool.h>
19#include <stddef.h>
20#include <stdint.h>
21#include <time.h>
22#include "mmhal_flash.h"
23#include "mmhal_wlan.h"
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
31
33void mmhal_init(void);
34
37{
41};
42
50{
51 LED_RED,
52 LED_GREEN,
53 LED_BLUE,
54 LED_WHITE
55};
56
59{
63};
64
66#define LED_OFF 0
67
75#define LED_ON 255
76
84
93void mmhal_log_write(const uint8_t *data, size_t len);
94
101
110uint32_t mmhal_random_u32(uint32_t min, uint32_t max);
111
113void mmhal_reset(void);
114
123void mmhal_set_led(uint8_t led, uint8_t level);
124
135void mmhal_set_error_led(bool state);
136
143{
144 BUTTON_ID_USER0
145};
146
151{
152 BUTTON_RELEASED,
153 BUTTON_PRESSED
154};
155
157typedef void (*mmhal_button_state_cb_t)(enum mmhal_button_id button_id,
158 enum mmhal_button_state button_state);
159
170 mmhal_button_state_cb_t button_state_cb);
171
179
187
188
203bool mmhal_get_hardware_version(char * version_buffer, size_t version_buffer_length);
204
214#define MMHAL_DEBUG_PIN(_pin_num) (1ul << (_pin_num))
215
217#define MMHAL_ALL_DEBUG_PINS (UINT32_MAX)
218
235void mmhal_set_debug_pins(uint32_t mask, uint32_t values);
236
243time_t mmhal_get_time(void);
244
258void mmhal_set_time(time_t epoch);
259
268enum mmhal_sleep_state mmhal_sleep_prepare(uint32_t expected_idle_time_ms);
269
278uint32_t mmhal_sleep(enum mmhal_sleep_state sleep_state, uint32_t expected_idle_time_ms);
279
289
294
298{
321};
322
335void mmhal_set_deep_sleep_veto(uint8_t veto_id);
336
345void mmhal_clear_deep_sleep_veto(uint8_t veto_id);
346
347#ifdef __cplusplus
348}
349#endif
350
bool mmhal_get_hardware_version(char *version_buffer, size_t version_buffer_length)
Reads information that can be used to identify the hardware platform, such as hardware ID and version...
uint32_t mmhal_sleep(enum mmhal_sleep_state sleep_state, uint32_t expected_idle_time_ms)
Function to enter MCU sleep.
mmhal_sleep_state
Enumeration of MCU sleep state.
Definition: mmhal.h:59
mmhal_isr_state
Enumeration of ISR states (i.e., whether in ISR or not).
Definition: mmhal.h:37
void(* mmhal_button_state_cb_t)(enum mmhal_button_id button_id, enum mmhal_button_state button_state)
Button state callback function prototype.
Definition: mmhal.h:157
void mmhal_set_deep_sleep_veto(uint8_t veto_id)
Sets a deep sleep veto that will prevent the device from entering deep sleep.
void mmhal_sleep_abort(enum mmhal_sleep_state sleep_state)
Function to abort the MCU sleep state.
void mmhal_sleep_cleanup(void)
Function to cleanup on exit from the MCU sleep state.
mmhal_led_id
Enumeration for different LED's on the board.
Definition: mmhal.h:50
mmhal_button_state
Enumeration for button states.
Definition: mmhal.h:151
bool mmhal_set_button_callback(enum mmhal_button_id button_id, mmhal_button_state_cb_t button_state_cb)
Registers a callback handler for button state changes.
void mmhal_log_write(const uint8_t *data, size_t len)
Write to the debug log.
void mmhal_log_flush(void)
Flush the debug log before returning.
void mmhal_set_time(time_t epoch)
Sets the RTC to the specified time in UTC.
mmhal_button_id
Enumeration for buttons on the board.
Definition: mmhal.h:143
mmhal_veto_id
Enumeration of veto_id ranges for use with mmhal_set_deep_sleep_veto() and mmhal_clear_deep_sleep_vet...
Definition: mmhal.h:298
mmhal_button_state_cb_t mmhal_get_button_callback(enum mmhal_button_id button_id)
Returns the registered callback handler for button state changes.
void mmhal_early_init(void)
Initialization before RTOS scheduler starts.
enum mmhal_sleep_state mmhal_sleep_prepare(uint32_t expected_idle_time_ms)
Function to prepare MCU to enter sleep.
void mmhal_set_error_led(bool state)
Set the error LED to the requested state.
void mmhal_set_led(uint8_t led, uint8_t level)
Set the specified LED to the requested level.
time_t mmhal_get_time(void)
Returns the time of day as set in the RTC.
enum mmhal_button_state mmhal_get_button(enum mmhal_button_id button_id)
Reads the state of the specified button.
uint32_t mmhal_random_u32(uint32_t min, uint32_t max)
Generate a random 32 bit integer within the given range.
enum mmhal_isr_state mmhal_get_isr_state(void)
Get the current ISR state (i.e., whether in ISR or not).
void mmhal_reset(void)
Reset the microcontroller.
void mmhal_clear_deep_sleep_veto(uint8_t veto_id)
Clears a deep sleep veto that was preventing the device from entering deep sleep (see mmhal_set_deep_...
void mmhal_init(void)
Initialization after RTOS scheduler started.
void mmhal_set_debug_pins(uint32_t mask, uint32_t values)
Set the value one or more debug pins.
@ MMHAL_SLEEP_DISABLED
Disable MCU sleep.
Definition: mmhal.h:60
@ MMHAL_SLEEP_SHALLOW
MCU to enter shallow sleep.
Definition: mmhal.h:61
@ MMHAL_SLEEP_DEEP
MCU can enter deep sleep.
Definition: mmhal.h:62
@ MMHAL_ISR_STATE_UNKNOWN
The HAL does not support checking ISR state.
Definition: mmhal.h:40
@ MMHAL_NOT_IN_ISR
The function was not executed from ISR context.
Definition: mmhal.h:38
@ MMHAL_IN_ISR
The function was executed from ISR context.
Definition: mmhal.h:39
@ MMHAL_VETO_ID_MORSELIB_MAX
End of deep sleep veto ID range that is allocated for morselib use.
Definition: mmhal.h:312
@ MMHAL_VETO_ID_APP_MAX
End of deep sleep veto ID range that is available for application use.
Definition: mmhal.h:302
@ MMHAL_VETO_ID_HAL_MAX
End of deep sleep veto ID range that is available for HAL use.
Definition: mmhal.h:306
@ MMHAL_VETO_ID_MMCONFIG
Deep sleep veto ID allocated to Morse Micro Persistent Configuration Store.
Definition: mmhal.h:316
@ MMHAL_VETO_ID_RESERVED_MIN
Start of deep sleep veto ID range reserved for future use.
Definition: mmhal.h:318
@ MMHAL_VETO_ID_DATALINK
Deep sleep veto ID for data-link subsystem.
Definition: mmhal.h:314
@ MMHAL_VETO_ID_MORSELIB_MIN
Start of deep sleep veto ID range that is allocated for morselib use.
Definition: mmhal.h:309
@ MMHAL_VETO_ID_RESERVED_MAX
End of deep sleep veto ID range reserved for future use.
Definition: mmhal.h:320
@ MMHAL_VETO_ID_HAL_MIN
Start of deep sleep veto ID range that is available for HAL use.
Definition: mmhal.h:304
@ MMHAL_VETO_ID_APP_MIN
Start of deep sleep veto ID range that is available for application use.
Definition: mmhal.h:300