The structure of BitMasher can be divided into two main parts: the platform and application.
The platform contains low-level code that manage the MCU's internal peripherals and the movement of data into and out of external peripherals (such as the audio codec and LCD display). It can be loosely thought of as the "kernel" or "back-end" of the system that supports the application layer.
The application is the main playable part of BitMasher. It contains the underlying code for the scenes and the controllers that run them. The application is analogous to an app that runs on your computer but in this case, there is only one app that ever runs and there is no operating system that manages the app's startup, execution and exit.
BitMasher has three states that the user can be in at any given time. Each state is managed by a controller. When the user interacts with a scene, the system is in the active state which is managed by the active controller (BM_Controller_Active). When the user is in the menu, the system is in the menu state (BM_Controller_Menu). Finally, when the device is sleeping/in low-power mode, it is in the sleep state (BM_Controller_Sleep). The diagram below shows the different states and the events that cause the transitions between the states:
While BitMasher is running, the audio and rendering engines operate in the background. However, when an audio buffer is filled or a scene update/frame render needs to be performed, there needs to be some way of communicating these events/requests to the controllers. In BitMasher's case, the audio and render engines pass messages into a queue which are read and processed by the controller.
More information about message handling is covered in the Controllers section.