1 /* 2 * Copyright 2021 QuickLogic 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 * 16 * SPDX-License-Identifier: Apache-2.0 17 */ 18 19 #ifndef DRIVERS_INCLUDE_UDMA_I2CM_DRIVER_H_ 20 #define DRIVERS_INCLUDE_UDMA_I2CM_DRIVER_H_ 21 22 #include <stdint.h> 23 #include <stdbool.h> 24 25 #include "hal_udma_ctrl_reg_defs.h" 26 27 #define SEMAPHORE_WAIT_TIME_IN_MS 10 28 29 typedef enum { 30 kI2cmReset 31 } udma_i2cm_control_type_t; 32 33 typedef enum { 34 kI2cmCmdStart = 0x00, 35 kI2cmCmdStop = 0x20, 36 kI2cmCmdRdAck = 0x40, 37 kI2cmCmdRdNack = 0x60, 38 kI2cmCmdWr = 0x80, 39 kI2cmCmdWait = 0xA0, 40 kI2cmCmdRpt = 0xC0, 41 kI2cmCmdCfg = 0xE0, 42 kI2cmCmdWaitEvt = 0x10, 43 } i2cm_cmd_t; 44 45 uint16_t udma_i2cm_open (uint8_t i2c_id, uint32_t i2c_clk_freq); 46 uint16_t udma_i2cm_close (uint8_t i2c_id); 47 uint16_t udma_i2cm_control(uint8_t i2c_id, udma_i2cm_control_type_t control_type, void* pparam); 48 uint8_t udma_i2cm_write(uint8_t i2c_id, uint8_t i2c_addr, uint8_t reg_addr, uint16_t write_len, uint8_t* write_data, bool more_follows); 49 uint8_t udma_i2cm_read(uint8_t i2c_id, uint8_t i2c_addr, uint8_t reg_addr, uint16_t read_len, uint8_t* read_buffer, bool more_follows); 50 uint8_t udma_i2cm_16read8(uint8_t i2c_id, uint8_t i2c_addr, uint16_t reg_addr, uint16_t read_len, uint8_t* read_buffer, bool more_follows); 51 52 53 54 // helper functions 55 uint8_t _udma_i2cm_write_addr_plus_regaddr (uint8_t i2c_id, uint8_t i2c_addr, uint8_t reg_addr); 56 uint8_t _udma_i2cm_write_addr_plus_reg16addr (uint8_t i2c_id, uint8_t i2c_addr, uint16_t reg_addr); 57 uint8_t _udma_i2cm_read(uint8_t i2c_id, uint8_t i2c_addr, uint16_t read_len, uint8_t* read_buffer, bool more_follows); 58 uint8_t _udma_i2cm_send_stop(uint8_t i2c_id); 59 60 #endif /* DRIVERS_INCLUDE_UDMA_I2CM_DRIVER_H_ */ 61 62