1 /* 2 * I2C support for the X1600. 3 * 4 * Copyright (C) 2017, 2018, 2019, 2023 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA 20 */ 21 22 #pragma once 23 24 #include <l4/sys/types.h> 25 #include <stdint.h> 26 27 28 29 #ifdef __cplusplus 30 31 #include <l4/devices/i2c-common.h> 32 33 // I2C channel. 34 35 class I2c_x1600_channel : public I2c_channel 36 { 37 public: 38 explicit I2c_x1600_channel(l4_addr_t start, enum Clock_identifiers clock, 39 Cpm_chip *cpm, uint32_t frequency); 40 }; 41 42 // I2C device control. 43 44 class I2c_x1600_chip : public I2c_chip 45 { 46 protected: 47 unsigned int num_channels() 48 { return 2; } 49 50 public: 51 explicit I2c_x1600_chip(l4_addr_t start, l4_addr_t end, Cpm_chip *cpm, 52 uint32_t frequency); 53 }; 54 55 #endif /* __cplusplus */ 56 57 58 59 /* C language interface. */ 60 61 EXTERN_C_BEGIN 62 63 void *x1600_i2c_init(l4_addr_t start, l4_addr_t end, void *cpm, 64 uint32_t frequency); 65 66 void *x1600_i2c_get_channel(void *i2c, uint8_t channel); 67 68 uint32_t x1600_i2c_get_frequency(void *i2c_channel); 69 70 void x1600_i2c_set_target(void *i2c_channel, uint8_t addr); 71 72 void x1600_i2c_start_read(void *i2c_channel, uint8_t buf[], unsigned int total, 73 int stop); 74 75 void x1600_i2c_read(void *i2c_channel); 76 77 void x1600_i2c_start_write(void *i2c_channel, uint8_t buf[], unsigned int total, 78 int stop); 79 80 void x1600_i2c_write(void *i2c_channel); 81 82 int x1600_i2c_read_done(void *i2c_channel); 83 84 int x1600_i2c_write_done(void *i2c_channel); 85 86 unsigned int x1600_i2c_have_read(void *i2c_channel); 87 88 unsigned int x1600_i2c_have_written(void *i2c_channel); 89 90 int x1600_i2c_failed(void *i2c_channel); 91 92 EXTERN_C_END