include/mgba/internal/ds/spi.h (view raw)
1/* Copyright (c) 2013-2017 Jeffrey Pfau
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6#ifndef DS_SPI_IO_H
7#define DS_SPI_IO_H
8
9#include <mgba-util/common.h>
10
11CXX_GUARD_START
12
13#include <mgba/core/log.h>
14#include <mgba/core/timing.h>
15
16mLOG_DECLARE_CATEGORY(DS_SPI);
17
18DECL_BITFIELD(DSSPICNT, uint16_t);
19DECL_BITS(DSSPICNT, Baud, 0, 2);
20DECL_BIT(DSSPICNT, Busy, 7);
21DECL_BITS(DSSPICNT, ChipSelect, 8, 2);
22DECL_BIT(DSSPICNT, TransferSize, 10);
23DECL_BIT(DSSPICNT, CSHold, 11);
24DECL_BIT(DSSPICNT, DoIRQ, 14);
25DECL_BIT(DSSPICNT, Enable, 15);
26
27DECL_BITFIELD(DSTSCControlByte, uint8_t);
28// TODO
29DECL_BITS(DSTSCControlByte, Channel, 4, 3);
30DECL_BIT(DSTSCControlByte, Control, 7);
31
32enum {
33 DS_SPI_DEV_POWERMAN = 0,
34 DS_SPI_DEV_FIRMWARE = 1,
35 DS_SPI_DEV_TSC = 2
36};
37
38enum {
39 DS_TSC_CHANNEL_TEMP_0 = 0,
40 DS_TSC_CHANNEL_TS_Y = 1,
41 DS_TSC_CHANNEL_BATTERY_V = 2,
42 DS_TSC_CHANNEL_TS_Z1 = 3,
43 DS_TSC_CHANNEL_TS_Z2 = 4,
44 DS_TSC_CHANNEL_TS_X = 5,
45 DS_TSC_CHANNEL_MIC = 6,
46 DS_TSC_CHANNEL_TEMP_1 = 7,
47};
48
49struct DSSPIBus {
50 bool holdEnabled;
51
52 uint8_t firmCommand;
53 uint8_t firmStatusReg;
54 int firmAddressingRemaining;
55 uint32_t firmAddress;
56
57 uint8_t tscControlByte;
58 uint16_t tscRegister;
59 int tscOffset;
60
61 uint8_t powmgrByte;
62
63 struct mTimingEvent event;
64};
65
66struct DS;
67void DSSPIReset(struct DS* ds);
68DSSPICNT DSSPIWriteControl(struct DS* ds, uint16_t control);
69void DSSPIWrite(struct DS* ds, uint8_t datum);
70
71CXX_GUARD_END
72
73#endif