1// Copyright 2018 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#pragma once
6
7#include <hwreg/bitfields.h>
8#include <zircon/types.h>
9
10namespace imx_i2c {
11
12class SlaveAddressReg : public hwreg::RegisterBase<SlaveAddressReg, uint16_t> {
13public:
14    DEF_FIELD(7, 1, address);
15    static auto Get() { return hwreg::RegisterAddr<SlaveAddressReg>(0x0); }
16};
17
18class FreqReg : public hwreg::RegisterBase<FreqReg, uint16_t> {
19public:
20    DEF_FIELD(5, 0, freq);
21    static auto Get() { return hwreg::RegisterAddr<FreqReg>(0x4); }
22};
23
24class ControlReg : public hwreg::RegisterBase<ControlReg, uint16_t, hwreg::EnablePrinter> {
25public:
26    DEF_BIT(7, enable);
27    DEF_BIT(6, interrupt_enable);
28    DEF_BIT(5, master);
29    DEF_BIT(4, transmit);
30    DEF_BIT(3, tx_ack_disable);
31    DEF_BIT(2, repeat_start);
32    static auto Get() { return hwreg::RegisterAddr<ControlReg>(0x8); }
33};
34
35class StatusReg : public hwreg::RegisterBase<StatusReg, uint16_t, hwreg::EnablePrinter> {
36public:
37    DEF_BIT(7, transfer_complete);
38    DEF_BIT(6, addressed_as_slave);
39    DEF_BIT(5, bus_busy);
40    DEF_BIT(4, arbitration_lost);
41    DEF_BIT(2, slave_read_write);
42    DEF_BIT(1, interrupt_pending);
43    DEF_BIT(0, ack);
44    static auto Get() { return hwreg::RegisterAddr<StatusReg>(0xC); }
45};
46
47// The register is 16 bits but since we only use 8 bits define as uint8_t to avoid casting
48class DataReg : public hwreg::RegisterBase<DataReg, uint8_t> {
49public:
50    DEF_FIELD(7, 0, data);
51    static auto Get() { return hwreg::RegisterAddr<DataReg>(0x10); }
52};
53
54} // namespace imx_i2c
55