YAHAL
Yet Another Hardware Abstraction Library
Loading...
Searching...
No Matches
i2c_msp432.h
1/*
2 * spi_msp432.h
3 *
4 * Created on: 14.06.2016
5 * Author: Andreas Terstegge
6 */
7
8#ifndef _I2C_MSP432_H_
9#define _I2C_MSP432_H_
10
11#include "msp.h"
12#include "gpio_msp432.h"
13#include "i2c_interface.h"
14
15namespace I2C {
16 const uint16_t OWN_7_BIT_ADDR = 0x0000;
17 const uint16_t OWN_10_BIT_ADDR = EUSCI_B_CTLW0_A10;
18 const uint16_t SLAVE_7_BIT_ADDR = 0x0000;
19 const uint16_t SLAVE_10_BIT_ADDR = EUSCI_B_CTLW0_SLA10;
20 const uint16_t MASTER_MODE = EUSCI_B_CTLW0_MST;
21 const uint16_t SLAVE_MODE = 0x0000;
22 const uint16_t CLK_ACLK = EUSCI_B_CTLW0_SSEL__ACLK;
23 const uint16_t CLK_SMCLK = EUSCI_B_CTLW0_SSEL__SMCLK;
24}
25
26class i2c_msp432 : public i2c_interface {
27
28public:
29
31 uint16_t mode = I2C::SLAVE_7_BIT_ADDR |
32 I2C::MASTER_MODE |
33 I2C::CLK_SMCLK);
34
35 virtual ~i2c_msp432();
36
37 int16_t i2cRead(uint16_t addr, uint8_t *rxbuf,
38 uint16_t len, bool sendStop = true) override;
39
40 int16_t i2cWrite(uint16_t addr, uint8_t *txbuf,
41 uint16_t len, bool sendStop = true) override;
42
43 void setSpeed(uint32_t) override;
44
45private:
46 bool _initialized;
47 void initialize();
48
49 // void send_ADR_ACK();
50 // void send_ADR_NACK();
51 void set_receiver();
52 void set_transmitter();
53 // void send_ACK();
54 // void send_NACK();
55 void send_START();
56 void send_STOP();
57
58 gpio_msp432 _sda;
59 gpio_msp432 _scl;
60
61 EUSCI_B_Type *_EUSCI;
62 uint16_t _mode;
63};
64
65#endif // _I2C_MSP432_H_
#define EUSCI_B_CTLW0_A10
#define EUSCI_B_CTLW0_SSEL__SMCLK
#define EUSCI_B_CTLW0_SSEL__ACLK
#define EUSCI_B_CTLW0_MST
#define EUSCI_B_CTLW0_SLA10