lws-bb-i2c.h (2119B)
1/* 2 * I2C - bitbanged generic gpio implementation 3 * 4 * Copyright (C) 2019 - 2020 Andy Green <andy@warmcat.com> 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a copy 7 * of this software and associated documentation files (the "Software"), to 8 * deal in the Software without restriction, including without limitation the 9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10 * sell copies of the Software, and to permit persons to whom the Software is 11 * furnished to do so, subject to the following conditions: 12 * 13 * The above copyright notice and this permission notice shall be included in 14 * all copies or substantial portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 22 * IN THE SOFTWARE. 23 * 24 * This is like an abstract class for gpio, a real implementation provides 25 * functions for the ops that use the underlying OS gpio arrangements. 26 */ 27 28typedef struct lws_bb_i2c { 29 lws_i2c_ops_t bb_ops; /* init to lws_bb_i2c_ops */ 30 31 /* implementation-specific members */ 32 33 _lws_plat_gpio_t scl; 34 _lws_plat_gpio_t sda; 35 36 const lws_gpio_ops_t *gpio; 37 void (*delay)(void); 38} lws_bb_i2c_t; 39 40#define lws_bb_i2c_ops \ 41 { \ 42 .init = lws_bb_i2c_init, \ 43 .start = lws_bb_i2c_start, \ 44 .stop = lws_bb_i2c_stop, \ 45 .write = lws_bb_i2c_write, \ 46 .read = lws_bb_i2c_read, \ 47 .set_ack = lws_bb_i2c_set_ack, \ 48 } 49 50int 51lws_bb_i2c_init(const lws_i2c_ops_t *octx); 52 53int 54lws_bb_i2c_start(const lws_i2c_ops_t *octx); 55 56void 57lws_bb_i2c_stop(const lws_i2c_ops_t *octx); 58 59int 60lws_bb_i2c_write(const lws_i2c_ops_t *octx, uint8_t data); 61 62int 63lws_bb_i2c_read(const lws_i2c_ops_t *octx); 64 65void 66lws_bb_i2c_set_ack(const lws_i2c_ops_t *octx, int ack);