-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsystem.h
More file actions
33 lines (26 loc) · 1.36 KB
/
Copy pathsystem.h
File metadata and controls
33 lines (26 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// system.h — Timer0 millisecond tick & Timer1 audio PWM engine.
//
// Timer0 (8-bit) drives systemGetTimeMs(), the uptime counter every other
// module paces itself against. Timer1 (16-bit, Fast PWM, TOP=ICR1) drives
// the raw variable-frequency square wave on PB1/OC1A; audio.c builds note
// choreography on top of the two functions exposed here.
#ifndef SYSTEM_H
#define SYSTEM_H
#include <stdint.h>
// Starts Timer0 in CTC mode as the 1ms system tick. See the implementation
// note in system.c: at F_CPU=20MHz an 8-bit timer can't hit exactly 1ms, so
// this is a ~0.16%-fast approximation, which is fine for game-loop pacing.
void systemInit(void);
// Milliseconds since systemInit(). Wraps after ~49.7 days. Safe to call
// from any context; reads are done with interrupts briefly disabled.
uint32_t systemGetTimeMs(void);
// Configures the hardware PWM duty cycle for the backlight on Timer1 OC1B
void systemBacklightSetBrightness(uint8_t percent);
// ---- Audio Engine (Timer1 / OC1A / PB1) --------------------------------
// Low-level tone generator. audio.c is the module that should normally be
// called by game/menu code; these are the primitives it builds on.
void systemAudioInit(void);
void systemAudioSetVolume(uint8_t vol);
void systemAudioSetFrequency(uint16_t freqHz); // 0 = silence
void systemAudioStop(void);
#endif // SYSTEM_H