Steffen Görtz | 9d68bf5 | 2019-01-29 11:46:03 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Microbit stub for Nordic Semiconductor nRF51 SoC Two-Wire Interface |
| 3 | * http://infocenter.nordicsemi.com/pdf/nRF51_RM_v3.0.1.pdf |
| 4 | * |
| 5 | * Copyright 2019 Red Hat, Inc. |
| 6 | * |
| 7 | * This code is licensed under the GPL version 2 or later. See |
| 8 | * the COPYING file in the top-level directory. |
| 9 | */ |
| 10 | |
| 11 | #ifndef MICROBIT_I2C_H |
| 12 | #define MICROBIT_I2C_H |
| 13 | |
| 14 | #include "hw/sysbus.h" |
| 15 | #include "hw/arm/nrf51.h" |
Eduardo Habkost | db1015e | 2020-09-03 16:43:22 -0400 | [diff] [blame] | 16 | #include "qom/object.h" |
Steffen Görtz | 9d68bf5 | 2019-01-29 11:46:03 +0000 | [diff] [blame] | 17 | |
| 18 | #define NRF51_TWI_TASK_STARTRX 0x000 |
| 19 | #define NRF51_TWI_TASK_STARTTX 0x008 |
| 20 | #define NRF51_TWI_TASK_STOP 0x014 |
| 21 | #define NRF51_TWI_EVENT_STOPPED 0x104 |
| 22 | #define NRF51_TWI_EVENT_RXDREADY 0x108 |
| 23 | #define NRF51_TWI_EVENT_TXDSENT 0x11c |
| 24 | #define NRF51_TWI_REG_ENABLE 0x500 |
| 25 | #define NRF51_TWI_REG_RXD 0x518 |
| 26 | #define NRF51_TWI_REG_TXD 0x51c |
| 27 | #define NRF51_TWI_REG_ADDRESS 0x588 |
| 28 | |
| 29 | #define TYPE_MICROBIT_I2C "microbit.i2c" |
Eduardo Habkost | 8063396 | 2020-09-16 14:25:19 -0400 | [diff] [blame] | 30 | OBJECT_DECLARE_SIMPLE_TYPE(MicrobitI2CState, MICROBIT_I2C) |
Steffen Görtz | 9d68bf5 | 2019-01-29 11:46:03 +0000 | [diff] [blame] | 31 | |
Philippe Mathieu-Daudé | 54595a5 | 2020-05-04 09:28:19 +0200 | [diff] [blame] | 32 | #define MICROBIT_I2C_NREGS (NRF51_PERIPHERAL_SIZE / sizeof(uint32_t)) |
Steffen Görtz | 9d68bf5 | 2019-01-29 11:46:03 +0000 | [diff] [blame] | 33 | |
Eduardo Habkost | db1015e | 2020-09-03 16:43:22 -0400 | [diff] [blame] | 34 | struct MicrobitI2CState { |
Steffen Görtz | 9d68bf5 | 2019-01-29 11:46:03 +0000 | [diff] [blame] | 35 | SysBusDevice parent_obj; |
| 36 | |
| 37 | MemoryRegion iomem; |
| 38 | uint32_t regs[MICROBIT_I2C_NREGS]; |
| 39 | uint32_t read_idx; |
Eduardo Habkost | db1015e | 2020-09-03 16:43:22 -0400 | [diff] [blame] | 40 | }; |
Steffen Görtz | 9d68bf5 | 2019-01-29 11:46:03 +0000 | [diff] [blame] | 41 | |
| 42 | #endif /* MICROBIT_I2C_H */ |