paul@190 | 1 | /* |
paul@190 | 2 | * I2C support for the X1600. |
paul@190 | 3 | * |
paul@190 | 4 | * Copyright (C) 2017, 2018, 2021, 2023 Paul Boddie <paul@boddie.org.uk> |
paul@190 | 5 | * |
paul@190 | 6 | * This program is free software; you can redistribute it and/or |
paul@190 | 7 | * modify it under the terms of the GNU General Public License as |
paul@190 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@190 | 9 | * the License, or (at your option) any later version. |
paul@190 | 10 | * |
paul@190 | 11 | * This program is distributed in the hope that it will be useful, |
paul@190 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@190 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@190 | 14 | * GNU General Public License for more details. |
paul@190 | 15 | * |
paul@190 | 16 | * You should have received a copy of the GNU General Public License |
paul@190 | 17 | * along with this program; if not, write to the Free Software |
paul@190 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@190 | 19 | * Boston, MA 02110-1301, USA |
paul@190 | 20 | */ |
paul@190 | 21 | |
paul@190 | 22 | #include <l4/devices/i2c-x1600.h> |
paul@190 | 23 | |
paul@190 | 24 | |
paul@190 | 25 | |
paul@190 | 26 | // Initialise a channel. |
paul@190 | 27 | |
paul@190 | 28 | I2c_x1600_channel::I2c_x1600_channel(l4_addr_t start, |
paul@203 | 29 | enum Clock_identifiers clock, |
paul@214 | 30 | Cpm_chip *cpm, |
paul@203 | 31 | uint32_t frequency) |
paul@214 | 32 | : I2c_channel(start, clock, cpm, frequency) |
paul@190 | 33 | { |
paul@190 | 34 | } |
paul@190 | 35 | |
paul@190 | 36 | |
paul@190 | 37 | |
paul@190 | 38 | // Initialise the I2C controller. |
paul@190 | 39 | |
paul@190 | 40 | I2c_x1600_chip::I2c_x1600_chip(l4_addr_t start, l4_addr_t end, |
paul@214 | 41 | Cpm_chip *cpm, |
paul@214 | 42 | uint32_t frequency) |
paul@214 | 43 | : I2c_chip(start, end, cpm, frequency) |
paul@190 | 44 | { |
paul@190 | 45 | } |
paul@190 | 46 | |
paul@190 | 47 | |
paul@190 | 48 | |
paul@190 | 49 | // C language interface functions. |
paul@190 | 50 | |
paul@190 | 51 | void *x1600_i2c_init(l4_addr_t start, l4_addr_t end, void *cpm, uint32_t frequency) |
paul@190 | 52 | { |
paul@214 | 53 | return (void *) new I2c_x1600_chip(start, end, static_cast<Cpm_chip *>(cpm), frequency); |
paul@190 | 54 | } |
paul@190 | 55 | |
paul@190 | 56 | void *x1600_i2c_get_channel(void *i2c, uint8_t channel) |
paul@190 | 57 | { |
paul@190 | 58 | return static_cast<I2c_x1600_chip *>(i2c)->get_channel(channel); |
paul@190 | 59 | } |
paul@190 | 60 | |
paul@190 | 61 | uint32_t x1600_i2c_get_frequency(void *i2c_channel) |
paul@190 | 62 | { |
paul@190 | 63 | return static_cast<I2c_x1600_channel *>(i2c_channel)->get_frequency(); |
paul@190 | 64 | } |
paul@190 | 65 | |
paul@190 | 66 | void x1600_i2c_set_target(void *i2c_channel, uint8_t addr) |
paul@190 | 67 | { |
paul@190 | 68 | static_cast<I2c_x1600_channel *>(i2c_channel)->set_target(addr); |
paul@190 | 69 | } |
paul@190 | 70 | |
paul@190 | 71 | void x1600_i2c_start_read(void *i2c_channel, uint8_t buf[], unsigned int total, |
paul@190 | 72 | int stop) |
paul@190 | 73 | { |
paul@190 | 74 | static_cast<I2c_x1600_channel *>(i2c_channel)->start_read(buf, total, stop); |
paul@190 | 75 | } |
paul@190 | 76 | |
paul@190 | 77 | void x1600_i2c_read(void *i2c_channel) |
paul@190 | 78 | { |
paul@190 | 79 | static_cast<I2c_x1600_channel *>(i2c_channel)->read(); |
paul@190 | 80 | } |
paul@190 | 81 | |
paul@190 | 82 | void x1600_i2c_start_write(void *i2c_channel, uint8_t buf[], unsigned int total, |
paul@190 | 83 | int stop) |
paul@190 | 84 | { |
paul@190 | 85 | static_cast<I2c_x1600_channel *>(i2c_channel)->start_write(buf, total, stop); |
paul@190 | 86 | } |
paul@190 | 87 | |
paul@190 | 88 | void x1600_i2c_write(void *i2c_channel) |
paul@190 | 89 | { |
paul@190 | 90 | static_cast<I2c_x1600_channel *>(i2c_channel)->write(); |
paul@190 | 91 | } |
paul@190 | 92 | |
paul@190 | 93 | int x1600_i2c_read_done(void *i2c_channel) |
paul@190 | 94 | { |
paul@190 | 95 | return static_cast<I2c_x1600_channel *>(i2c_channel)->read_done(); |
paul@190 | 96 | } |
paul@190 | 97 | |
paul@190 | 98 | int x1600_i2c_write_done(void *i2c_channel) |
paul@190 | 99 | { |
paul@190 | 100 | return static_cast<I2c_x1600_channel *>(i2c_channel)->write_done(); |
paul@190 | 101 | } |
paul@190 | 102 | |
paul@190 | 103 | unsigned int x1600_i2c_have_read(void *i2c_channel) |
paul@190 | 104 | { |
paul@190 | 105 | return static_cast<I2c_x1600_channel *>(i2c_channel)->have_read(); |
paul@190 | 106 | } |
paul@190 | 107 | |
paul@190 | 108 | unsigned int x1600_i2c_have_written(void *i2c_channel) |
paul@190 | 109 | { |
paul@190 | 110 | return static_cast<I2c_x1600_channel *>(i2c_channel)->have_written(); |
paul@190 | 111 | } |
paul@190 | 112 | |
paul@190 | 113 | int x1600_i2c_failed(void *i2c_channel) |
paul@190 | 114 | { |
paul@190 | 115 | return static_cast<I2c_x1600_channel *>(i2c_channel)->failed(); |
paul@190 | 116 | } |
paul@216 | 117 | |
paul@216 | 118 | void x1600_i2c_stop(void *i2c_channel) |
paul@216 | 119 | { |
paul@216 | 120 | static_cast<I2c_x1600_channel *>(i2c_channel)->stop(); |
paul@216 | 121 | } |