diff options
author | Andre Marques <andre.lousa.marques@gmail.com> | 2015-09-05 21:53:16 +0100 |
---|---|---|
committer | Gedare Bloom <gedare@rtems.org> | 2015-09-25 16:36:52 -0400 |
commit | 7aca0fefce41f2090ffbd2f7ee2fbfcc9f2d1f0d (patch) | |
tree | 0b21847e289cb557ca0bba23d6b925a967af2864 /c/src/lib/libbsp/arm/raspberrypi/include/i2c.h | |
parent | Added GPIO API sources to rpi Makefile (diff) | |
download | rtems-7aca0fefce41f2090ffbd2f7ee2fbfcc9f2d1f0d.tar.bz2 |
RaspberryPi: Added I2C and SPI bus support.
Further documentation can be found in
https://devel.rtems.org/wiki/GSoC/2015/RaspberryPi_peripherals_and_SD_card
and test data (including sample user applications, device drivers and wiring schemes) can be found in
https://github.com/asuol/RTEMS_rpi_testing
Diffstat (limited to 'c/src/lib/libbsp/arm/raspberrypi/include/i2c.h')
-rw-r--r-- | c/src/lib/libbsp/arm/raspberrypi/include/i2c.h | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/c/src/lib/libbsp/arm/raspberrypi/include/i2c.h b/c/src/lib/libbsp/arm/raspberrypi/include/i2c.h new file mode 100644 index 0000000000..4a8dbbf2ac --- /dev/null +++ b/c/src/lib/libbsp/arm/raspberrypi/include/i2c.h @@ -0,0 +1,95 @@ +/** + * @file i2c.h + * + * @ingroup raspberrypi_i2c + * + * @brief Raspberry Pi specific I2C definitions. + */ + +/* + * Copyright (c) 2014-2015 Andre Marques <andre.lousa.marques at gmail.com> + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.org/license/LICENSE. + */ + +#ifndef LIBBSP_ARM_RASPBERRYPI_I2C_H +#define LIBBSP_ARM_RASPBERRYPI_I2C_H + +#include <dev/i2c/i2c.h> + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @name I2C constants. + * + * @{ + */ + +/** + * @brief BSC controller core clock rate in Hz. + * + * This is set to 150 MHz as per the BCM2835 datasheet. + */ +#define BSC_CORE_CLK_HZ 150000000 + +/** + * @brief Default bus clock. + * + * This sets the bus with a 100 kHz clock speed. + */ +#define DEFAULT_BUS_CLOCK 100000 + +/** @} */ + +/** + * @name I2C directives. + * + * @{ + */ + +/** + * @brief Setups the Raspberry Pi GPIO header to activate the BSC I2C bus. + */ +extern void rpi_i2c_init(void); + +/** + * @brief Registers the Raspberry Pi BSC I2C bus with the + * Linux I2C User-Space API. + * + * @param[in] bus_path Path to the bus device file. + * @param[in] bus_clock Bus clock in Hz. + * + * @retval 0 Bus registered successfully. + * @retval <0 Could not register the bus. The return value is a negative + * errno code. + */ +extern int rpi_i2c_register_bus( + const char *bus_path, + uint32_t bus_clock +); + +/** + * @brief Setups the Raspberry Pi BSC I2C bus (located on the GPIO header) + * on the "/dev/i2c" device file, using the default bus clock. + * + * @retval 0 Bus configured and registered successfully. + * @retval <0 See @see rpi_i2c_register_bus(). + */ +static inline int rpi_setup_i2c_bus(void) +{ + rpi_i2c_init(); + + return rpi_i2c_register_bus("/dev/i2c", DEFAULT_BUS_CLOCK); +} + +/** @} */ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* LIBBSP_ARM_RASPBERRYPI_I2C_H */ |