Skip to content

Commit

Permalink
stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
celerizer committed Oct 7, 2024
1 parent 3ffb045 commit d881c43
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
26 changes: 21 additions & 5 deletions devices/bma150.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ static const h8_device_id type = H8_DEVICE_BMA150;
typedef struct
{
h8_byte_t data[0x80];

union
{
H8_BITFIELD_2
Expand All @@ -18,22 +19,34 @@ typedef struct
) parts;
h8_byte_t raw;
} state;

/* ROM tries to read immediately after sending control byte, when it should
* send a don't care data byte first. This flag is a hack to keep track.
* Not sure if this is correct behavior, but it seems like it should only
* read bytes 0 and 1 on boot, while without this check also reads 2 */
h8_bool read_next;

h8_bool selected;
} h8_bma150_t;

#define H8_BMA150_WRITING 0
#define H8_BMA150_READING 1

void h8_bma150_select_pin(h8_device_t *device, h8_bool on)
{
h8_bma150_t *bma = device->device;

bma->selected = !on;
}

/** 4.1.1 Four-wire SPI interface - Figure 7 */
void h8_bma150_read(h8_device_t *device, h8_byte_t *dst)
{
h8_bma150_t *bma = device->device;

/* ROM tries to read immediately after sending control byte, when it should
* send a don't care data byte first. This flag is a hack to keep track.
* Not sure if this is correct behavior, but it seems like it should only
* read bytes 0 and 1 on boot, while without this check also reads 2 */
if (bma->read_next)
if (!bma->selected)
return;
else if (bma->read_next)
bma->read_next = FALSE;
else if (bma->state.parts.mode == H8_BMA150_READING)
*dst = bma->data[bma->state.parts.addr];
Expand All @@ -44,6 +57,9 @@ void h8_bma150_write(h8_device_t *device, h8_byte_t *dst, const h8_byte_t value)
{
h8_bma150_t *bma = device->device;

if (!bma->selected)
return;

bma->read_next = FALSE;

if (bma->state.parts.mode == H8_BMA150_WRITING && bma->state.parts.addr)
Expand Down
19 changes: 19 additions & 0 deletions devices/lcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,27 @@ static const h8_device_id type = H8_DEVICE_LCD;
typedef struct
{
h8_u8 vram[128 * 64];
h8_bool selected;
h8_bool mode;
} h8_lcd_t;

#define H8_LCD_MODE_CMD 0
#define H8_LCD_MODE_DATA 1

void h8_lcd_select_pin(h8_device_t *device, const h8_bool on)
{
h8_lcd_t *m_lcd = device->device;

m_lcd->selected = !on;
}

void h8_lcd_mode_pin(h8_device_t *device, const h8_bool on)
{
h8_lcd_t *m_lcd = device->device;

m_lcd->mode = on;
}

void h8_lcd_read(h8_device_t *device, h8_byte_t *dst)
{
h8_lcd_t *m_lcd = device->device;
Expand Down

0 comments on commit d881c43

Please sign in to comment.