-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathhal.h
More file actions
89 lines (77 loc) · 2.78 KB
/
hal.h
File metadata and controls
89 lines (77 loc) · 2.78 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
* TamaLIB - A hardware agnostic Tamagotchi P1 emulation library
*
* Copyright (C) 2021 Jean-Christophe Rona <jc@rona.fr>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef _HAL_H_
#define _HAL_H_
#include "hal_types.h"
#ifndef NULL
#define NULL 0
#endif
typedef enum {
LOG_ERROR = 0x1,
LOG_INFO = (0x1 << 1),
LOG_MEMORY = (0x1 << 2),
LOG_CPU = (0x1 << 3),
} log_level_t;
/* The Hardware Abstraction Layer
* NOTE: This structure acts as an abstraction layer between TamaLIB and the OS/SDK.
* All pointers MUST be implemented, but some implementations can be left empty.
*/
typedef struct {
/* Memory allocation functions
* NOTE: Needed only if breakpoints support is required.
*/
//void * (*malloc)(u32_t size);
//void (*free)(void *ptr);
/* What to do if the CPU has halted
*/
void (*halt)(void);
/* Log related function
* NOTE: Needed only if log messages are required.
*/
//bool_t (*is_log_enabled)(log_level_t level);
void (*log)(log_level_t level, char *buff, ...);
/* Clock related functions
* NOTE: Timestamps granularity is configured with tamalib_init(), an accuracy
* of ~30 us (1/32768) is required for a cycle accurate emulation.
*/
void (*sleep_until)(timestamp_t ts);
timestamp_t (*get_timestamp)(void);
/* Screen related functions
* NOTE: In case of direct hardware access to pixels, the set_XXXX() functions
* (called for each pixel/icon update) can directly drive them, otherwise they
* should just store the data in a buffer and let update_screen() do the actual
* rendering (at 30 fps).
*/
void (*update_screen)(void);
void (*set_lcd_matrix)(u8_t x, u8_t y, bool_t val);
void (*set_lcd_icon)(u8_t icon, bool_t val);
/* Sound related functions
* NOTE: set_frequency() changes the output frequency of the sound, while
* play_frequency() decides whether the sound should be heard or not.
*/
void (*set_frequency)(u32_t freq);
void (*play_frequency)(bool_t en);
/* Event handler from the main app (if any)
* NOTE: This function usually handles button related events, states loading/saving ...
*/
int (*handler)(void);
} hal_t;
extern hal_t *g_hal;
#endif /* _HAL_H_ */