mbed library sources, include can_api for nucleo-f091rc

Dependents:   CanNucleoF0_example

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Wed Jul 29 09:45:09 2015 +0100
Revision:
598:2d5fc5624619
Synchronized with git revision e87fec7b35d45d8663318a40a4a9fb58f91d0237

Full URL: https://github.com/mbedmicro/mbed/commit/e87fec7b35d45d8663318a40a4a9fb58f91d0237/

Microbit addition

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 598:2d5fc5624619 1 /* Copyright (c) 2009 Nordic Semiconductor. All Rights Reserved.
mbed_official 598:2d5fc5624619 2 *
mbed_official 598:2d5fc5624619 3 * The information contained herein is property of Nordic Semiconductor ASA.
mbed_official 598:2d5fc5624619 4 * Terms and conditions of usage are described in detail in NORDIC
mbed_official 598:2d5fc5624619 5 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
mbed_official 598:2d5fc5624619 6 *
mbed_official 598:2d5fc5624619 7 * Licensees are granted free, non-transferable use of the information. NO
mbed_official 598:2d5fc5624619 8 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
mbed_official 598:2d5fc5624619 9 * the file.
mbed_official 598:2d5fc5624619 10 *
mbed_official 598:2d5fc5624619 11 */
mbed_official 598:2d5fc5624619 12
mbed_official 598:2d5fc5624619 13 #ifndef TWI_MASTER_H
mbed_official 598:2d5fc5624619 14 #define TWI_MASTER_H
mbed_official 598:2d5fc5624619 15
mbed_official 598:2d5fc5624619 16
mbed_official 598:2d5fc5624619 17 #ifdef __cplusplus
mbed_official 598:2d5fc5624619 18 extern "C" {
mbed_official 598:2d5fc5624619 19 #endif
mbed_official 598:2d5fc5624619 20
mbed_official 598:2d5fc5624619 21 /*lint ++flb "Enter library region" */
mbed_official 598:2d5fc5624619 22
mbed_official 598:2d5fc5624619 23 #include <stdbool.h>
mbed_official 598:2d5fc5624619 24 #include <stdint.h>
mbed_official 598:2d5fc5624619 25
mbed_official 598:2d5fc5624619 26 /** @file
mbed_official 598:2d5fc5624619 27 * @brief Software controlled TWI Master driver.
mbed_official 598:2d5fc5624619 28 *
mbed_official 598:2d5fc5624619 29 *
mbed_official 598:2d5fc5624619 30 * @defgroup lib_driver_twi_master Software controlled TWI Master driver
mbed_official 598:2d5fc5624619 31 * @{
mbed_official 598:2d5fc5624619 32 * @ingroup nrf_drivers
mbed_official 598:2d5fc5624619 33 * @brief Software controlled TWI Master driver.
mbed_official 598:2d5fc5624619 34 *
mbed_official 598:2d5fc5624619 35 * Supported features:
mbed_official 598:2d5fc5624619 36 * - Repeated start
mbed_official 598:2d5fc5624619 37 * - No multi-master
mbed_official 598:2d5fc5624619 38 * - Only 7-bit addressing
mbed_official 598:2d5fc5624619 39 * - Supports clock stretching (with optional SMBus style slave timeout)
mbed_official 598:2d5fc5624619 40 * - Tries to handle slaves stuck in the middle of transfer
mbed_official 598:2d5fc5624619 41 */
mbed_official 598:2d5fc5624619 42
mbed_official 598:2d5fc5624619 43 #define TWI_READ_BIT (0x01) //!< If this bit is set in the address field, transfer direction is from slave to master.
mbed_official 598:2d5fc5624619 44
mbed_official 598:2d5fc5624619 45 #define TWI_ISSUE_STOP ((bool)true) //!< Parameter for @ref twi_master_transfer
mbed_official 598:2d5fc5624619 46 #define TWI_DONT_ISSUE_STOP ((bool)false) //!< Parameter for @ref twi_master_transfer
mbed_official 598:2d5fc5624619 47
mbed_official 598:2d5fc5624619 48 /* These macros are needed to see if the slave is stuck and we as master send dummy clock cycles to end its wait */
mbed_official 598:2d5fc5624619 49 /*lint -e717 -save "Suppress do {} while (0) for these macros" */
mbed_official 598:2d5fc5624619 50 /*lint ++flb "Enter library region" */
mbed_official 598:2d5fc5624619 51 #define TWI_SCL_HIGH() do { NRF_GPIO->OUTSET = (1UL << TWI_MASTER_CONFIG_CLOCK_PIN_NUMBER); } while(0) /*!< Pulls SCL line high */
mbed_official 598:2d5fc5624619 52 #define TWI_SCL_LOW() do { NRF_GPIO->OUTCLR = (1UL << TWI_MASTER_CONFIG_CLOCK_PIN_NUMBER); } while(0) /*!< Pulls SCL line low */
mbed_official 598:2d5fc5624619 53 #define TWI_SDA_HIGH() do { NRF_GPIO->OUTSET = (1UL << TWI_MASTER_CONFIG_DATA_PIN_NUMBER); } while(0) /*!< Pulls SDA line high */
mbed_official 598:2d5fc5624619 54 #define TWI_SDA_LOW() do { NRF_GPIO->OUTCLR = (1UL << TWI_MASTER_CONFIG_DATA_PIN_NUMBER); } while(0) /*!< Pulls SDA line low */
mbed_official 598:2d5fc5624619 55 #define TWI_SDA_INPUT() do { NRF_GPIO->DIRCLR = (1UL << TWI_MASTER_CONFIG_DATA_PIN_NUMBER); } while(0) /*!< Configures SDA pin as input */
mbed_official 598:2d5fc5624619 56 #define TWI_SDA_OUTPUT() do { NRF_GPIO->DIRSET = (1UL << TWI_MASTER_CONFIG_DATA_PIN_NUMBER); } while(0) /*!< Configures SDA pin as output */
mbed_official 598:2d5fc5624619 57 #define TWI_SCL_OUTPUT() do { NRF_GPIO->DIRSET = (1UL << TWI_MASTER_CONFIG_CLOCK_PIN_NUMBER); } while(0) /*!< Configures SCL pin as output */
mbed_official 598:2d5fc5624619 58 /*lint -restore */
mbed_official 598:2d5fc5624619 59
mbed_official 598:2d5fc5624619 60 #define TWI_SDA_READ() ((NRF_GPIO->IN >> TWI_MASTER_CONFIG_DATA_PIN_NUMBER) & 0x1UL) /*!< Reads current state of SDA */
mbed_official 598:2d5fc5624619 61 #define TWI_SCL_READ() ((NRF_GPIO->IN >> TWI_MASTER_CONFIG_CLOCK_PIN_NUMBER) & 0x1UL) /*!< Reads current state of SCL */
mbed_official 598:2d5fc5624619 62
mbed_official 598:2d5fc5624619 63 #define TWI_DELAY() nrf_delay_us(4) /*!< Time to wait when pin states are changed. For fast-mode the delay can be zero and for standard-mode 4 us delay is sufficient. */
mbed_official 598:2d5fc5624619 64
mbed_official 598:2d5fc5624619 65
mbed_official 598:2d5fc5624619 66 /**
mbed_official 598:2d5fc5624619 67 * @brief Function for initializing TWI bus IO pins and checks if the bus is operational.
mbed_official 598:2d5fc5624619 68 *
mbed_official 598:2d5fc5624619 69 * Both pins are configured as Standard-0, No-drive-1 (open drain).
mbed_official 598:2d5fc5624619 70 *
mbed_official 598:2d5fc5624619 71 * @return
mbed_official 598:2d5fc5624619 72 * @retval true TWI bus is clear for transfers.
mbed_official 598:2d5fc5624619 73 * @retval false TWI bus is stuck.
mbed_official 598:2d5fc5624619 74 */
mbed_official 598:2d5fc5624619 75 bool twi_master_init_and_clear(void);
mbed_official 598:2d5fc5624619 76
mbed_official 598:2d5fc5624619 77 /**
mbed_official 598:2d5fc5624619 78 * @brief Function for transferring data over TWI bus.
mbed_official 598:2d5fc5624619 79 *
mbed_official 598:2d5fc5624619 80 * If TWI master detects even one NACK from the slave or timeout occurs, STOP condition is issued
mbed_official 598:2d5fc5624619 81 * and the function returns false.
mbed_official 598:2d5fc5624619 82 * Bit 0 (@ref TWI_READ_BIT) in the address parameter controls transfer direction;
mbed_official 598:2d5fc5624619 83 * - If 1, master reads data_length number of bytes from the slave
mbed_official 598:2d5fc5624619 84 * - If 0, master writes data_length number of bytes to the slave.
mbed_official 598:2d5fc5624619 85 *
mbed_official 598:2d5fc5624619 86 * @note Make sure at least data_length number of bytes is allocated in data if TWI_READ_BIT is set.
mbed_official 598:2d5fc5624619 87 * @note @ref TWI_ISSUE_STOP
mbed_official 598:2d5fc5624619 88 *
mbed_official 598:2d5fc5624619 89 * @param address Data transfer direction (LSB) / Slave address (7 MSBs).
mbed_official 598:2d5fc5624619 90 * @param data Pointer to data.
mbed_official 598:2d5fc5624619 91 * @param data_length Number of bytes to transfer.
mbed_official 598:2d5fc5624619 92 * @param issue_stop_condition If @ref TWI_ISSUE_STOP, STOP condition is issued before exiting function. If @ref TWI_DONT_ISSUE_STOP, STOP condition is not issued before exiting function. If transfer failed for any reason, STOP condition will be issued in any case.
mbed_official 598:2d5fc5624619 93 * @return
mbed_official 598:2d5fc5624619 94 * @retval true Data transfer succeeded without errors.
mbed_official 598:2d5fc5624619 95 * @retval false Data transfer failed.
mbed_official 598:2d5fc5624619 96 */
mbed_official 598:2d5fc5624619 97 bool twi_master_transfer(uint8_t address, uint8_t *data, uint8_t data_length, bool issue_stop_condition);
mbed_official 598:2d5fc5624619 98
mbed_official 598:2d5fc5624619 99 /**
mbed_official 598:2d5fc5624619 100 *@}
mbed_official 598:2d5fc5624619 101 **/
mbed_official 598:2d5fc5624619 102
mbed_official 598:2d5fc5624619 103 #ifdef __cplusplus
mbed_official 598:2d5fc5624619 104 }
mbed_official 598:2d5fc5624619 105 #endif
mbed_official 598:2d5fc5624619 106
mbed_official 598:2d5fc5624619 107 /*lint --flb "Leave library region" */
mbed_official 598:2d5fc5624619 108 #endif //TWI_MASTER_H