mirror of
https://github.com/apache/nuttx.git
synced 2026-09-28 15:54:57 +08:00
drivers: add generic i2c bitbang driver
This commit is contained in:
@@ -38,6 +38,47 @@ config I2C_NTRACE
|
||||
default 32
|
||||
depends on I2C_TRACE
|
||||
|
||||
config I2C_BITBANG
|
||||
bool "I2C bitbang implementation"
|
||||
default n
|
||||
---help---
|
||||
Enable support for a bitbang implementation of I2C
|
||||
|
||||
if I2C_BITBANG
|
||||
|
||||
config I2C_BITBANG_NO_DELAY
|
||||
bool "Do not add delay"
|
||||
default n
|
||||
---help---
|
||||
If you want to go full speed (depending on how fast pins can be toggled)
|
||||
you can enable this option. This will not respect the desired frequency
|
||||
set during the I2C transfer operation.
|
||||
|
||||
config I2C_BITBANG_GPIO_OVERHEAD
|
||||
int "GPIO overhead"
|
||||
depends on !I2C_BITBANG_NO_DELAY
|
||||
default 0
|
||||
---help---
|
||||
Overhead of GPIO toggling operation to consider when computing
|
||||
delays. This overhead will be subtracted from sleep times to achieve
|
||||
desired frquency.
|
||||
|
||||
config I2C_BITBANG_TIMEOUT
|
||||
int "I2C timeout"
|
||||
default 1000
|
||||
---help---
|
||||
Timeout (microseconds) to abort wait on slave
|
||||
|
||||
config I2C_BITBANG_CLOCK_STRETCHING
|
||||
bool "Support clock stretching"
|
||||
default n
|
||||
---help---
|
||||
This enables I2C clock stretching. This requires the hardware to set
|
||||
the pin into open-collector mode (master sets SCL high and waits until
|
||||
slave stops holding it low).
|
||||
|
||||
endif # I2C_BITBANG
|
||||
|
||||
config I2C_DRIVER
|
||||
bool "I2C character driver"
|
||||
default n
|
||||
|
||||
@@ -44,6 +44,10 @@ ifeq ($(CONFIG_I2C_DRIVER),y)
|
||||
CSRCS += i2c_driver.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_I2C_BITBANG),y)
|
||||
CSRCS += i2c_bitbang.c
|
||||
endif
|
||||
|
||||
# Include the selected I2C multiplexer drivers
|
||||
|
||||
ifeq ($(CONFIG_I2CMULTIPLEXER_PCA9540BDP),y)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,82 @@
|
||||
/****************************************************************************
|
||||
* drivers/i2c/i2c_bitbang.h
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __DRIVERS_I2C_I2C_BITBANG_H
|
||||
#define __DRIVERS_I2C_I2C_BITBANG_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/i2c/i2c_master.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
struct i2c_bitbang_lower_dev_s;
|
||||
|
||||
struct i2c_bitbang_lower_ops_s
|
||||
{
|
||||
/* Initialize pins to appropriate state (usually open-drain) */
|
||||
|
||||
CODE void (*initialize)(FAR struct i2c_bitbang_lower_dev_s *lower);
|
||||
|
||||
/* Set high/low level for SCL/SDA pins */
|
||||
|
||||
CODE void (*set_scl)(FAR struct i2c_bitbang_lower_dev_s *lower, bool high);
|
||||
CODE void (*set_sda)(FAR struct i2c_bitbang_lower_dev_s *lower, bool high);
|
||||
|
||||
/* Read level of SCL/SDA pins */
|
||||
|
||||
CODE bool (*get_scl)(FAR struct i2c_bitbang_lower_dev_s *lower);
|
||||
CODE bool (*get_sda)(FAR struct i2c_bitbang_lower_dev_s *lower);
|
||||
};
|
||||
|
||||
struct i2c_bitbang_lower_dev_s
|
||||
{
|
||||
FAR const struct i2c_bitbang_lower_ops_s *ops;
|
||||
FAR void *priv;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: i2c_bitbang_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize a bitbang I2C device instance
|
||||
*
|
||||
* Input Parameters:
|
||||
* lower - Lower half of driver
|
||||
*
|
||||
* Returned Value:
|
||||
* Pointer to a the I2C instance
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR struct i2c_master_s *i2c_bitbang_initialize(
|
||||
FAR struct i2c_bitbang_lower_dev_s *lower);
|
||||
|
||||
#endif /* __DRIVERS_I2C_I2C_BITBANG_H */
|
||||
Reference in New Issue
Block a user