Swadge 2024 2.0.0
APIs to develop games for the Magfest Swadge
Loading...
Searching...
No Matches
swadge2024.h
Go to the documentation of this file.
1
160
161#ifndef _SWADGE_MODE_H_
162#define _SWADGE_MODE_H_
163
164// Standard C includes
165#include <stdint.h>
166#include <inttypes.h>
167#include <stdbool.h>
168#include <stdlib.h>
169#include <stdio.h>
170#include <string.h>
171#include <math.h>
172
173// Useful ESP things
174#include <esp_heap_caps.h>
175#include <esp_log.h>
176#include <esp_random.h>
177
178// Hardware interfaces
179#include "crashwrap.h"
180#include "hdw-imu.h"
181#include "hdw-battmon.h"
182#include "hdw-btn.h"
183#include "hdw-ch32v003.h"
184#include "hdw-dac.h"
185#include "hdw-esp-now.h"
186#include "hdw-led.h"
187#include "hdw-mic.h"
188#include "hdw-nvs.h"
189#include "hdw-temperature.h"
190#include "hdw-tft.h"
191#include "hdw-usb.h"
192
193// Drawing interfaces
194#include "palette.h"
195#include "color_utils.h"
196#include "font.h"
197#include "wsg.h"
198#include "shapes.h"
199#include "fill.h"
200#include "menu.h"
201#include "menuManiaRenderer.h"
202#include "menuMegaRenderer.h"
203
204// Asset loaders
205#include "cnfs.h"
206#include "fs_wsg.h"
207#include "fs_font.h"
208#include "fs_txt.h"
209#include "fs_json.h"
210
211// Connection interface
212#include "p2pConnection.h"
213
214// General utilities
215#include "linked_list.h"
216#include "macros.h"
217#include "trigonometry.h"
218#include "vector2d.h"
219#include "geometry.h"
220#include "settingsManager.h"
221#include "touchUtils.h"
222#include "vectorFl2d.h"
223#include "geometryFl.h"
224#include "imu_utils.h"
225#include "swadgePass.h"
226#include "trophy.h"
227#include "helpPages.h"
228
229// Sound utilities
230#include "soundFuncs.h"
231#include "swSynth.h"
232#include "midiPlayer.h"
233
234#define EXIT_TIME_US 1000000
236#define DEFAULT_FRAME_RATE_US (1000000 / 40)
237
238// Forward declaration
239struct swadgePassPacket;
240
246typedef struct swadgeMode
247{
251 const char* modeName;
252
259
265
271
277
284
288 void (*fnEnterMode)(void);
289
293 void (*fnExitMode)(void);
294
301 void (*fnMainLoop)(int64_t elapsedUs);
302
310 void (*fnAudioCallback)(uint16_t* samples, uint32_t sampleCnt);
311
322 void (*fnBackgroundDrawCallback)(int16_t x, int16_t y, int16_t w, int16_t h, int16_t up, int16_t upNum);
323
332 void (*fnEspNowRecvCb)(const esp_now_recv_info_t* esp_now_info, const uint8_t* data, uint8_t len, int8_t rssi);
333
341 void (*fnEspNowSendCb)(const uint8_t* mac_addr, esp_now_send_status_t status);
342
353 int16_t (*fnAdvancedUSB)(uint8_t* buffer, uint16_t length, uint8_t isGet);
354
360
371
377
379
380void switchToSwadgeMode(const swadgeMode_t* mode);
382
383void deinitSystem(void);
384
385void openQuickSettings(void);
386void setFrameRateUs(uint32_t newFrameRateUs);
387uint32_t getFrameRateUs(void);
388
389void switchToSpeaker(void);
390void switchToMicrophone(void);
391
392void powerDownPeripherals(void);
393void powerUpPeripherals(void);
394
395// Getters
396font_t* getSysFont(void);
398
399#endif
A font is a collection of font_ch_t for all ASCII characters. Each character has the same height and ...
Definition font.h:66
A button event containing the button that triggered the event, whether it was pressed or released,...
Definition hdw-btn.h:117
void(* fnDacCallback_t)(uint8_t *samples, int16_t len)
A callback which requests DAC samples from the application.
Definition hdw-dac.h:94
wifiMode_t
The different WiFi modes.
Definition hdw-esp-now.h:99
Contains information which applies to the entire MIDI file.
Definition midiFileParser.h:87
A struct of all the function pointers necessary for a swadge mode. If a mode does not need a particul...
void powerDownPeripherals(void)
Power down all hardware peripherals.
Definition swadge2024.c:965
wifiMode_t wifiMode
This is a setting, not a function pointer. Set it to NO_WIFI to save power by not using WiFi at all....
Definition swadge2024.h:258
void setFrameRateUs(uint32_t newFrameRateUs)
Set the framerate, in microseconds.
Definition swadge2024.c:885
const char * modeName
This swadge mode's name, used in menus. This is not a function pointer.
Definition swadge2024.h:251
void softSwitchToPendingSwadge(void)
Switch to the pending Swadge mode without restarting the system.
Definition swadge2024.c:786
void(* fnAudioCallback)(uint16_t *samples, uint32_t sampleCnt)
This function is called whenever audio samples are read from the microphone (ADC) and are ready for p...
Definition swadge2024.h:310
fnDacCallback_t fnDacCb
This function is called to fill sample buffers for the DAC. If this is NULL, then globalMidiPlayerFil...
Definition swadge2024.h:359
bool checkButtonQueueWrapper(buttonEvt_t *evt)
Service the queue of button events that caused interrupts This only returns a single event,...
Definition swadge2024.c:833
void switchToMicrophone(void)
Enable the microphone and disable the speaker (and battery monitor)
Definition swadge2024.c:943
midiFile_t * getSysSound(void)
void switchToSwadgeMode(const swadgeMode_t *mode)
Definition swadge2024.c:775
bool overrideSelectBtn
If this is false, then PB_SELECT events will only be used to return to the main menu or open the quic...
Definition swadge2024.h:283
const trophyDataList_t * trophyData
A struct with the settings and data required for trophy behavior. Set to NULL for no trophies.
Definition swadge2024.h:375
void(* fnEspNowRecvCb)(const esp_now_recv_info_t *esp_now_info, const uint8_t *data, uint8_t len, int8_t rssi)
This function is called whenever an ESP-NOW packet is received.
Definition swadge2024.h:332
void deinitSystem(void)
Deinitialize all components in the system.
Definition swadge2024.c:673
bool overrideUsb
If this is false, then the default TinyUSB driver will be installed (HID gamepad)....
Definition swadge2024.h:264
void(* fnBackgroundDrawCallback)(int16_t x, int16_t y, int16_t w, int16_t h, int16_t up, int16_t upNum)
This function is called when the display driver wishes to update a section of the display.
Definition swadge2024.h:322
void powerUpPeripherals(void)
Power up all hardware peripherals.
Definition swadge2024.c:982
void(* fnAddToSwadgePassPacket)(struct swadgePassPacket *packet)
This function is called to fill in a SwadgePass packet with mode-specific data. The Swadge mode shoul...
Definition swadge2024.h:370
uint32_t getFrameRateUs(void)
Get the current framerate, in microseconds.
Definition swadge2024.c:895
bool usesThermometer
If this is false, the thermometer will not be initialized and readTemperatureSensor() will not work....
Definition swadge2024.h:276
void(* fnExitMode)(void)
This function is called when the mode is exited. It should free any allocated memory.
Definition swadge2024.h:293
font_t * getSysFont(void)
Get the Sys Ibm Font. Font is pre-loaded fto ensure a font is always available for devs to use.
Definition swadge2024.c:1022
bool usesAccelerometer
If this is false, the accelerometer will not be initialized and accelGetAccelVec() will not work....
Definition swadge2024.h:270
void(* fnEnterMode)(void)
This function is called when this mode is started. It should initialize variables and start the mode.
Definition swadge2024.h:288
void(* fnEspNowSendCb)(const uint8_t *mac_addr, esp_now_send_status_t status)
This function is called whenever an ESP-NOW packet is sent. It is just a status callback whether or n...
Definition swadge2024.h:341
void switchToSpeaker(void)
Enable the speaker (and battery monitor) and disable the microphone.
Definition swadge2024.c:924
void(* fnMainLoop)(int64_t elapsedUs)
This function is called from the main loop. It's pretty quick, but the timing may be inconsistent.
Definition swadge2024.h:301
void openQuickSettings(void)
Definition swadge2024.c:872
int16_t(* fnAdvancedUSB)(uint8_t *buffer, uint16_t length, uint8_t isGet)
Advanced USB Functionality, for hooking existing advanced_usb interface.
Definition swadge2024.h:353
Definition swadge2024.h:247
A SwadgePass packet which is transmitted over ESP NOW.
Definition swadgePass.h:121
Trophies for swadge modes.
The data object dev hands to the trophy showcase that contains all the const data.
Definition trophy.h:328