Loading...
Searching...
No Matches
periph_gba.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2023-2026 HAW Hamburg
3 * SPDX-License-Identifier: LGPL-2.1-only
4 */
5
6#pragma once
7
17
18#include <stdint.h>
19
20#include "assert.h"
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
29#define REG32(ADDR) (*(uint32_t volatile(*))(ADDR))
30
34#define REG16(ADDR) (*(uint16_t volatile(*))(ADDR))
35
39#define MEM16(ADDR) ((uint16_t(*))(ADDR))
40
44#define GBA_PTR_TO_IRQ_HANDLER REG32(0x3007ffc)
45
66#define GBA_IE REG16(0x4000200)
67
71#define GBA_IE_TIMERS (0x0F << 3)
72
93#define GBA_IF REG16(0x4000202)
94
98#define GBA_IF_CLEAR_ALL (0x3FFF)
99
103#define GBA_IF_TIMERS (0x0F << 3)
104
110#define GBA_IME REG16(0x4000208) /* Technically 32 bit reg, but only bit 0 is used */
111
116#define GBA_TM0_CNT_L REG16(0x4000100)
117#define GBA_TM0_CNT_H REG16(0x4000102)
118#define GBA_TM1_CNT_L REG16(0x4000104)
119#define GBA_TM1_CNT_H REG16(0x4000106)
120#define GBA_TM2_CNT_L REG16(0x4000108)
121#define GBA_TM2_CNT_H REG16(0x400010A)
122#define GBA_TM3_CNT_L REG16(0x400010C)
123#define GBA_TM3_CNT_H REG16(0x400010E)
125
129#define GBA_TIMER_MAX_TICKS (0xFFFF)
130
135#define GBA_TIMER_FRQ_16K (16400lu)
136#define GBA_TIMER_FRQ_65K (65500lu)
137#define GBA_TIMER_FRQ_262K (262200lu)
138#define GBA_TIMER_FRQ_16M (16780000lu)
140
144typedef struct {
145 uint16_t current_value;
146 uint16_t prescaler : 2;
149 uint16_t unused_3_5 : 3;
150 uint16_t irq_enable : 1;
151 uint16_t run : 1;
152 uint16_t unused_8_15 : 8;
153} gba_timer;
154/* I don't trust bit-fields over all compilers & toolchains */
155static_assert(sizeof(gba_timer) == 4, "2 x Timer register should be 4 bytes");
156
160typedef volatile gba_timer gba_timer_t;
161
166#define GBA_TIMER_0 ((gba_timer_t *)0x4000100)
167#define GBA_TIMER_1 ((gba_timer_t *)0x4000104)
168#define GBA_TIMER_2 ((gba_timer_t *)0x4000108)
169#define GBA_TIMER_3 ((gba_timer_t *)0x400010C)
171
176#define GBA_SCREEN_WIDTH (240)
177#define GBA_SCREEN_HEIGHT (160)
179
183#define GBA_DISPCNT REG16(0x4000000)
184
189#define GBA_DISPCNT_BGMODE_0 0x0000
190#define GBA_DISPCNT_BGMODE_1 0x0001
191#define GBA_DISPCNT_BGMODE_2 0x0002
192#define GBA_DISPCNT_BGMODE_3 0x0003
193#define GBA_DISPCNT_BGMODE_4 0x0004
194#define GBA_DISPCNT_BGMODE_5 0x0005
195
196#define GBA_DISPCNT_SDBG_0 0x0100
197#define GBA_DISPCNT_SDBG_1 0x0200
198#define GBA_DISPCNT_SDBG_2 0x0400
199#define GBA_DISPCNT_SDBG_3 0x0800
200
201#define GBA_DISPCNT_SDOBJ 0x1000
203
207#define GBA_DISPSTAT REG16(0x4000004)
208
213#define GBA_BG0CNT REG16(0x4000008)
214#define GBA_BG1CNT REG16(0x400000a)
215#define GBA_BG2CNT REG16(0x400000c)
216#define GBA_BG3CNT REG16(0x400000e)
218
222#define GBA_VRAM_PALETTE MEM16(0x5000000)
223
227#define GBA_VRAM MEM16(0x6000000)
228
229#ifdef __cplusplus
230}
231#endif
232
POSIX.1-2008 compliant version of the assert macro.
volatile gba_timer gba_timer_t
The type for the GBA timers.
Definition periph_gba.h:160
Struct whose members map onto the timer register.
Definition periph_gba.h:144
uint16_t prescaler
The prescaler sets the divider for this timer.
Definition periph_gba.h:146
uint16_t count_up_on_neighbour_overflow
If set, counts up this timer when the previous overflowed.
Definition periph_gba.h:147
uint16_t unused_8_15
unused
Definition periph_gba.h:152
uint16_t unused_3_5
unused
Definition periph_gba.h:149
uint16_t irq_enable
enables interrupt request for this timer on overflow
Definition periph_gba.h:150
uint16_t run
starts the timer
Definition periph_gba.h:151
uint16_t current_value
The counter / current value of this timer.
Definition periph_gba.h:145