Morse Micro IoT SDK  2.10.4
emmet.c
Go to the documentation of this file.
1/*
2 * Copyright 2021-2023 Morse Micro
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
73#include <string.h>
74#include "mmhal_app.h"
75#include "mmosal.h"
76#include "mmwlan.h"
77#include "mmregdb.h"
78#include "emmet.h"
79#include "mm_app_loadconfig.h"
80#include "mm_app_common.h"
81
82#include "mmipal.h"
83
89static void link_status_callback(const struct mmipal_link_status *link_status)
90{
91 uint32_t time_ms = mmosal_get_time_ms();
92 if (link_status->link_state == MMIPAL_LINK_UP)
93 {
94 printf("Link is up. Time: %lu ms", time_ms);
95 printf(", IP: %s", link_status->ip_addr);
96 printf(", Netmask: %s", link_status->netmask);
97 printf(", Gateway: %s\n", link_status->gateway);
98 }
99 else
100 {
101 printf("Link is down. Time: %lu ms\n", time_ms);
102 }
103}
104
105void emmet_hal_set_led(uint8_t led_id, uint8_t level)
106{
107 mmhal_set_led(led_id, level);
108}
109
111{
112 enum mmhal_button_state state = mmhal_get_button(BUTTON_ID_USER0);
113 if (state == BUTTON_RELEASED)
114 {
116 }
117 else
118 {
120 }
121}
122
124{
126 if (cb != NULL)
127 {
128 if (state == EMMET_BUTTON_RELEASED)
129 {
130 cb(BUTTON_ID_USER0, BUTTON_RELEASED);
131 }
132 else
133 {
134 cb(BUTTON_ID_USER0, BUTTON_PRESSED);
135 }
136 }
137}
138
143void app_init(void)
144{
145 /* Initialize Emmet first to ensure host interface is in a valid state. */
146 emmet_init();
147
148 printf("\n\nMorse Emmet Demo (Built " __DATE__ " " __TIME__ ")\n\n");
149
150 /* Initialize MMWLAN interface */
151 mmwlan_init();
153
154 /* Boot the WLAN interface so that we can retrieve the firmware version. */
155 struct mmwlan_boot_args boot_args = MMWLAN_BOOT_ARGS_INIT;
156 (void)mmwlan_boot(&boot_args);
158
159 /* Load IP stack settings from config store or defaults */
162
163 /* Initialize IP stack. */
165 {
166 printf("Error initializing network interface.\n");
167 MMOSAL_ASSERT(false);
168 }
169
171
172 /* Configure and start Emmet so that we can begin receiving commands from the host. */
173 emmet_set_reg_db(get_regulatory_db());
174
175 emmet_start();
176}
static void link_status_callback(const struct mmipal_link_status *link_status)
Link status callback.
Definition: emmet.c:89
void app_init(void)
Main entry point to the application.
Definition: emmet.c:143
void emmet_hal_trigger_button_event(enum emmet_button_state state)
Trigger a button event to the application as if a user had pushed or released the button.
Definition: emmet.c:123
void emmet_hal_set_led(uint8_t led_id, uint8_t level)
Set LED state.
Definition: emmet.c:105
enum emmet_button_state emmet_hal_get_button_state(void)
Get the current button state.
Definition: emmet.c:110
void emmet_start(void)
Start Emmet.
enum mmwlan_status emmet_set_reg_db(const struct mmwlan_regulatory_db *reg_db)
Set the regulatory database for Emmet to use.
void emmet_init(void)
Initialize Emmet.
emmet_button_state
Enumeration of button states used by the Emmet HAL.
Definition: emmet.h:101
@ EMMET_BUTTON_PRESSED
Button pressed state.
Definition: emmet.h:105
@ EMMET_BUTTON_RELEASED
Button released state.
Definition: emmet.h:103
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_app.h:97
mmhal_button_state
Enumeration for button states.
Definition: mmhal_app.h:91
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_set_led(uint8_t led, uint8_t level)
Set the specified LED to the requested level.
enum mmhal_button_state mmhal_get_button(enum mmhal_button_id button_id)
Reads the state of the specified button.
enum mmipal_status mmipal_init(const struct mmipal_init_args *args)
Initialize the IP stack and enable the MMWLAN interface.
#define MMIPAL_INIT_ARGS_DEFAULT
Default values for mmipal_init_args.
Definition: mmipal.h:199
void mmipal_set_link_status_callback(mmipal_link_status_cb_fn_t fn)
Sets the callback function to be invoked on link status changes.
@ MMIPAL_LINK_UP
Link is up.
Definition: mmipal.h:62
@ MMIPAL_SUCCESS
Completed successfully.
Definition: mmipal.h:45
#define MMOSAL_ASSERT(expr)
Assert that the given expression evaluates to true and abort execution if not.
Definition: mmosal.h:934
uint32_t mmosal_get_time_ms(void)
Get the system time in milliseconds.
enum mmwlan_status mmwlan_boot(const struct mmwlan_boot_args *args)
Boot the Morse Micro transceiver and leave it in an idle state.
#define MMWLAN_BOOT_ARGS_INIT
Initializer for mmwlan_boot_args.
Definition: mmwlan.h:616
void mmwlan_init(void)
Initialize the MMWLAN subsystem.
enum mmwlan_status mmwlan_set_channel_list(const struct mmwlan_s1g_channel_list *channel_list)
Set the list of channels that are supported by the regulatory domain in which the device resides.
Morse Micro application helper routines for initializing/de-initializing the Wireless LAN interface a...
void app_print_version_info(void)
Prints various version information.
const struct mmwlan_s1g_channel_list * load_channel_list(void)
Looks up country code and returns appropriate channel list.
void load_mmipal_init_args(struct mmipal_init_args *args)
Loads the provided structure with initialization parameters read from config store.
Initialize arguments structure.
Definition: mmipal.h:175
Arguments data structure for mmwlan_boot().
Definition: mmwlan.h:606