mirror of https://github.com/ARMmbed/mbed-os.git
[ALL TARGETS] error replaced by assert for preconditions
parent
fb90157c9a
commit
d843d56c08
|
@ -397,11 +397,13 @@ extern "C" WEAK void __cxa_pure_virtual(void) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "mbed_interface.h"
|
#include "mbed_interface.h"
|
||||||
|
// mbed abort invokes only mbed die. The abort function is called from failing assert for example.
|
||||||
|
namespace std {
|
||||||
extern "C" void abort(void) {
|
extern "C" void abort(void) {
|
||||||
mbed_die();
|
mbed_die();
|
||||||
while(1);
|
while(1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ****************************************************************************
|
// ****************************************************************************
|
||||||
// mbed_main is a function that is called before main()
|
// mbed_main is a function that is called before main()
|
||||||
|
|
|
@ -116,6 +116,10 @@ void serial_baud(serial_t *obj, int baudrate) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits) {
|
void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits) {
|
||||||
|
assert((stop_bits == 1) || (stop_bits == 2));
|
||||||
|
assert(parity < (ParityEven + 1));
|
||||||
|
assert((data_bits == 8) || (data_bits == 9));
|
||||||
|
assert((data_bits == 2) && (obj->index != 0));
|
||||||
|
|
||||||
// save C2 state
|
// save C2 state
|
||||||
uint32_t c2_state = (obj->uart->C2 & (UART_C2_RE_MASK | UART_C2_TE_MASK));
|
uint32_t c2_state = (obj->uart->C2 & (UART_C2_RE_MASK | UART_C2_TE_MASK));
|
||||||
|
@ -124,9 +128,6 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b
|
||||||
obj->uart->C2 &= ~(UART_C2_RE_MASK | UART_C2_TE_MASK);
|
obj->uart->C2 &= ~(UART_C2_RE_MASK | UART_C2_TE_MASK);
|
||||||
|
|
||||||
// 8 data bits = 0 ... 9 data bits = 1
|
// 8 data bits = 0 ... 9 data bits = 1
|
||||||
if ((data_bits < 8) || (data_bits > 9))
|
|
||||||
error("Invalid number of bits (%d) in serial format, should be 8..9", data_bits);
|
|
||||||
|
|
||||||
data_bits -= 8;
|
data_bits -= 8;
|
||||||
|
|
||||||
uint32_t parity_enable, parity_select;
|
uint32_t parity_enable, parity_select;
|
||||||
|
@ -135,22 +136,15 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b
|
||||||
case ParityOdd : parity_enable = 1; parity_select = 1; data_bits++; break;
|
case ParityOdd : parity_enable = 1; parity_select = 1; data_bits++; break;
|
||||||
case ParityEven: parity_enable = 1; parity_select = 0; data_bits++; break;
|
case ParityEven: parity_enable = 1; parity_select = 0; data_bits++; break;
|
||||||
default:
|
default:
|
||||||
error("Invalid serial parity setting");
|
break;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1 stop bits = 0, 2 stop bits = 1
|
|
||||||
if ((stop_bits != 1) && (stop_bits != 2))
|
|
||||||
error("Invalid stop bits specified");
|
|
||||||
stop_bits -= 1;
|
stop_bits -= 1;
|
||||||
|
|
||||||
uint32_t m10 = 0;
|
uint32_t m10 = 0;
|
||||||
|
|
||||||
// 9 data bits + parity
|
// 9 data bits + parity
|
||||||
if (data_bits == 2) {
|
if (data_bits == 2) {
|
||||||
// only uart0 supports 10 bit communication
|
|
||||||
if (obj->index != 0)
|
|
||||||
error("Invalid number of bits (9) to be used with parity");
|
|
||||||
data_bits = 0;
|
data_bits = 0;
|
||||||
m10 = 1;
|
m10 = 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,13 +91,8 @@ void spi_free(spi_t *obj) {
|
||||||
// [TODO]
|
// [TODO]
|
||||||
}
|
}
|
||||||
void spi_format(spi_t *obj, int bits, int mode, int slave) {
|
void spi_format(spi_t *obj, int bits, int mode, int slave) {
|
||||||
if ((bits != 8) && (bits != 16)) {
|
assert((bits == 8) || (bits == 16));
|
||||||
error("Only 8/16 bits SPI supported");
|
assert((mode > -1) && (mode < 4));
|
||||||
}
|
|
||||||
|
|
||||||
if ((mode < 0) || (mode > 3)) {
|
|
||||||
error("SPI mode unsupported");
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t polarity = (mode & 0x2) ? 1 : 0;
|
uint32_t polarity = (mode & 0x2) ? 1 : 0;
|
||||||
uint32_t phase = (mode & 0x1) ? 1 : 0;
|
uint32_t phase = (mode & 0x1) ? 1 : 0;
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
|
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
|
|
||||||
static const PinMap PinMap_SPI_SCLK[] = {
|
static const PinMap PinMap_SPI_SCLK[] = {
|
||||||
{PTB0, SPI_0, 3},
|
{PTB0, SPI_0, 3},
|
||||||
|
@ -51,9 +50,7 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
|
||||||
SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel);
|
SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel);
|
||||||
|
|
||||||
obj->spi = (SPI_Type*)pinmap_merge(spi_data, spi_cntl);
|
obj->spi = (SPI_Type*)pinmap_merge(spi_data, spi_cntl);
|
||||||
if ((int)obj->spi == NC) {
|
assert((int)obj->spi != NC);
|
||||||
error("SPI pinout mapping failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
// enable power and clocking
|
// enable power and clocking
|
||||||
switch ((int)obj->spi) {
|
switch ((int)obj->spi) {
|
||||||
|
@ -87,13 +84,8 @@ void spi_free(spi_t *obj) {
|
||||||
// [TODO]
|
// [TODO]
|
||||||
}
|
}
|
||||||
void spi_format(spi_t *obj, int bits, int mode, int slave) {
|
void spi_format(spi_t *obj, int bits, int mode, int slave) {
|
||||||
if (bits != 8) {
|
assert(bits == 8);
|
||||||
error("Only 8bits SPI supported");
|
assert((mode > -1) && (mode < 4));
|
||||||
}
|
|
||||||
|
|
||||||
if ((mode < 0) || (mode > 3)) {
|
|
||||||
error("SPI mode unsupported");
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t polarity = (mode & 0x2) ? 1 : 0;
|
uint8_t polarity = (mode & 0x2) ? 1 : 0;
|
||||||
uint8_t phase = (mode & 0x1) ? 1 : 0;
|
uint8_t phase = (mode & 0x1) ? 1 : 0;
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
|
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
#include "clk_freqs.h"
|
#include "clk_freqs.h"
|
||||||
#include "PeripheralPins.h"
|
#include "PeripheralPins.h"
|
||||||
|
|
||||||
|
@ -33,9 +32,7 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
|
||||||
SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel);
|
SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel);
|
||||||
|
|
||||||
obj->spi = (SPI_Type*)pinmap_merge(spi_data, spi_cntl);
|
obj->spi = (SPI_Type*)pinmap_merge(spi_data, spi_cntl);
|
||||||
if ((int)obj->spi == NC) {
|
assert((int)obj->spi != NC);
|
||||||
error("SPI pinout mapping failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
// enable power and clocking
|
// enable power and clocking
|
||||||
switch ((int)obj->spi) {
|
switch ((int)obj->spi) {
|
||||||
|
@ -67,13 +64,8 @@ void spi_free(spi_t *obj) {
|
||||||
// [TODO]
|
// [TODO]
|
||||||
}
|
}
|
||||||
void spi_format(spi_t *obj, int bits, int mode, int slave) {
|
void spi_format(spi_t *obj, int bits, int mode, int slave) {
|
||||||
if (bits != 8) {
|
assert(bits == 8);
|
||||||
error("Only 8bits SPI supported");
|
assert((mode > -1) && (mode < 4));
|
||||||
}
|
|
||||||
|
|
||||||
if ((mode < 0) || (mode > 3)) {
|
|
||||||
error("SPI mode unsupported");
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t polarity = (mode & 0x2) ? 1 : 0;
|
uint8_t polarity = (mode & 0x2) ? 1 : 0;
|
||||||
uint8_t phase = (mode & 0x1) ? 1 : 0;
|
uint8_t phase = (mode & 0x1) ? 1 : 0;
|
||||||
|
|
|
@ -13,13 +13,13 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "spi_api.h"
|
#include "spi_api.h"
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
|
|
||||||
static const PinMap PinMap_SPI_SCLK[] = {
|
static const PinMap PinMap_SPI_SCLK[] = {
|
||||||
{PTA15, SPI_0, 2},
|
{PTA15, SPI_0, 2},
|
||||||
|
@ -90,9 +90,7 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
|
||||||
SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel);
|
SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel);
|
||||||
|
|
||||||
obj->spi = (SPI_Type*)pinmap_merge(spi_data, spi_cntl);
|
obj->spi = (SPI_Type*)pinmap_merge(spi_data, spi_cntl);
|
||||||
if ((int)obj->spi == NC) {
|
assert((int)obj->spi != NC);
|
||||||
error("SPI pinout mapping failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
// enable power and clocking
|
// enable power and clocking
|
||||||
switch ((int)obj->spi) {
|
switch ((int)obj->spi) {
|
||||||
|
@ -125,13 +123,8 @@ void spi_free(spi_t *obj) {
|
||||||
// [TODO]
|
// [TODO]
|
||||||
}
|
}
|
||||||
void spi_format(spi_t *obj, int bits, int mode, int slave) {
|
void spi_format(spi_t *obj, int bits, int mode, int slave) {
|
||||||
if ((bits != 8) && (bits != 16)) {
|
assert((bits == 8) || (bits == 16));
|
||||||
error("Only 8/16 bits SPI supported");
|
assert((mode > -1) && (mode < 4));
|
||||||
}
|
|
||||||
|
|
||||||
if ((mode < 0) || (mode > 3)) {
|
|
||||||
error("SPI mode unsupported");
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t polarity = (mode & 0x2) ? 1 : 0;
|
uint8_t polarity = (mode & 0x2) ? 1 : 0;
|
||||||
uint8_t phase = (mode & 0x1) ? 1 : 0;
|
uint8_t phase = (mode & 0x1) ? 1 : 0;
|
||||||
|
|
|
@ -43,7 +43,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
|
||||||
I2CName i2c_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA);
|
I2CName i2c_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA);
|
||||||
I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
|
I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
|
||||||
obj->i2c = (I2C_Type*)pinmap_merge(i2c_sda, i2c_scl);
|
obj->i2c = (I2C_Type*)pinmap_merge(i2c_sda, i2c_scl);
|
||||||
assert(obj->i2c != (PinName)NC);
|
assert((int)obj->i2c != NC);
|
||||||
|
|
||||||
// enable power
|
// enable power
|
||||||
switch ((int)obj->i2c) {
|
switch ((int)obj->i2c) {
|
||||||
|
|
|
@ -148,6 +148,9 @@ void serial_baud(serial_t *obj, int baudrate) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits) {
|
void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits) {
|
||||||
|
assert((stop_bits == 1) || (stop_bits == 2));
|
||||||
|
assert(parity < (ParityEven + 1));
|
||||||
|
assert(data_bits == 8); // TODO: Support other number of data bits (also in the write method!)
|
||||||
|
|
||||||
// save C2 state
|
// save C2 state
|
||||||
uint8_t c2_state = (obj->uart->C2 & (UARTLP_C2_RE_MASK | UARTLP_C2_TE_MASK));
|
uint8_t c2_state = (obj->uart->C2 & (UARTLP_C2_RE_MASK | UARTLP_C2_TE_MASK));
|
||||||
|
@ -155,10 +158,6 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b
|
||||||
// Disable UART before changing registers
|
// Disable UART before changing registers
|
||||||
obj->uart->C2 &= ~(UARTLP_C2_RE_MASK | UARTLP_C2_TE_MASK);
|
obj->uart->C2 &= ~(UARTLP_C2_RE_MASK | UARTLP_C2_TE_MASK);
|
||||||
|
|
||||||
// TODO: Support other number of data bits (also in the write method!)
|
|
||||||
if ((data_bits < 8) || (data_bits > 8)) {
|
|
||||||
error("Invalid number of bits (%d) in serial format, should be 8", data_bits);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t parity_enable, parity_select;
|
uint8_t parity_enable, parity_select;
|
||||||
switch (parity) {
|
switch (parity) {
|
||||||
|
@ -166,14 +165,9 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b
|
||||||
case ParityOdd : parity_enable = 1; parity_select = 1; data_bits++; break;
|
case ParityOdd : parity_enable = 1; parity_select = 1; data_bits++; break;
|
||||||
case ParityEven: parity_enable = 1; parity_select = 0; data_bits++; break;
|
case ParityEven: parity_enable = 1; parity_select = 0; data_bits++; break;
|
||||||
default:
|
default:
|
||||||
error("Invalid serial parity setting");
|
break;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1 stop bits = 0, 2 stop bits = 1
|
|
||||||
if ((stop_bits != 1) && (stop_bits != 2)) {
|
|
||||||
error("Invalid stop bits specified");
|
|
||||||
}
|
|
||||||
stop_bits -= 1;
|
stop_bits -= 1;
|
||||||
|
|
||||||
// data bits, parity and parity mode
|
// data bits, parity and parity mode
|
||||||
|
|
|
@ -43,7 +43,7 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void gpio_dir(gpio_t *obj, PinDirection direction) {
|
void gpio_dir(gpio_t *obj, PinDirection direction) {
|
||||||
assert(pin != (PinName)NC);
|
assert(obj->pin != (PinName)NC);
|
||||||
switch (direction) {
|
switch (direction) {
|
||||||
case PIN_INPUT :
|
case PIN_INPUT :
|
||||||
*obj->reg_dir &= ~obj->mask;
|
*obj->reg_dir &= ~obj->mask;
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "analogin_api.h"
|
#include "analogin_api.h"
|
||||||
#include "wait_api.h"
|
#include "wait_api.h"
|
||||||
|
|
||||||
|
@ -32,7 +33,6 @@
|
||||||
|
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
|
|
||||||
static const PinMap PinMap_ADC[] = {
|
static const PinMap PinMap_ADC[] = {
|
||||||
{PA_0, ADC_1, STM_PIN_DATA(GPIO_Mode_AN, GPIO_OType_PP, GPIO_PuPd_NOPULL, 0xFF)}, // ADC_IN0
|
{PA_0, ADC_1, STM_PIN_DATA(GPIO_Mode_AN, GPIO_OType_PP, GPIO_PuPd_NOPULL, 0xFF)}, // ADC_IN0
|
||||||
|
@ -53,10 +53,7 @@ void analogin_init(analogin_t *obj, PinName pin) {
|
||||||
|
|
||||||
// Get the peripheral name (ADC_1, ADC_2...) from the pin and assign it to the object
|
// Get the peripheral name (ADC_1, ADC_2...) from the pin and assign it to the object
|
||||||
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
|
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
|
||||||
|
assert(obj->adc != (ADCName)NC);
|
||||||
if (obj->adc == (ADCName)NC) {
|
|
||||||
error("ADC pin mapping failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configure GPIO
|
// Configure GPIO
|
||||||
pinmap_pinout(pin, PinMap_ADC);
|
pinmap_pinout(pin, PinMap_ADC);
|
||||||
|
|
|
@ -27,13 +27,13 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "i2c_api.h"
|
#include "i2c_api.h"
|
||||||
|
|
||||||
#if DEVICE_I2C
|
#if DEVICE_I2C
|
||||||
|
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
|
|
||||||
/* Timeout values for flags and events waiting loops. These timeouts are
|
/* Timeout values for flags and events waiting loops. These timeouts are
|
||||||
not based on accurate values, they just guarantee that the application will
|
not based on accurate values, they just guarantee that the application will
|
||||||
|
@ -57,10 +57,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
|
||||||
I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
|
I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
|
||||||
|
|
||||||
obj->i2c = (I2CName)pinmap_merge(i2c_sda, i2c_scl);
|
obj->i2c = (I2CName)pinmap_merge(i2c_sda, i2c_scl);
|
||||||
|
assert(obj->i2c != (I2CName)NC);
|
||||||
if (obj->i2c == (I2CName)NC) {
|
|
||||||
error("I2C pin mapping failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable I2C clock
|
// Enable I2C clock
|
||||||
if (obj->i2c == I2C_1) {
|
if (obj->i2c == I2C_1) {
|
||||||
|
@ -84,6 +81,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void i2c_frequency(i2c_t *obj, int hz) {
|
void i2c_frequency(i2c_t *obj, int hz) {
|
||||||
|
assert((hz == 100000) || (hz == 200000) || (hz == 400000)); //"Only 100kHz, 200kHz and 400kHz I2C frequencies are supported."
|
||||||
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
|
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
|
||||||
I2C_InitTypeDef I2C_InitStructure;
|
I2C_InitTypeDef I2C_InitStructure;
|
||||||
uint32_t tim = 0;
|
uint32_t tim = 0;
|
||||||
|
@ -101,7 +99,6 @@ void i2c_frequency(i2c_t *obj, int hz) {
|
||||||
tim = 0x0010020A; // Fast mode
|
tim = 0x0010020A; // Fast mode
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
error("Only 100kHz, 200kHz and 400kHz I2C frequencies are supported.");
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,10 +27,10 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "serial_api.h"
|
#include "serial_api.h"
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
static const PinMap PinMap_UART_TX[] = {
|
static const PinMap PinMap_UART_TX[] = {
|
||||||
|
@ -78,10 +78,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
|
||||||
|
|
||||||
// Get the peripheral name (UART_1, UART_2, ...) from the pin and assign it to the object
|
// Get the peripheral name (UART_1, UART_2, ...) from the pin and assign it to the object
|
||||||
obj->uart = (UARTName)pinmap_merge(uart_tx, uart_rx);
|
obj->uart = (UARTName)pinmap_merge(uart_tx, uart_rx);
|
||||||
|
assert(obj->uart != (UARTName)NC);
|
||||||
if (obj->uart == (UARTName)NC) {
|
|
||||||
error("Serial pinout mapping failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable USART clock
|
// Enable USART clock
|
||||||
if (obj->uart == UART_1) {
|
if (obj->uart == UART_1) {
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "spi_api.h"
|
#include "spi_api.h"
|
||||||
|
|
||||||
#if DEVICE_SPI
|
#if DEVICE_SPI
|
||||||
|
@ -34,7 +35,6 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
|
|
||||||
static const PinMap PinMap_SPI_MOSI[] = {
|
static const PinMap PinMap_SPI_MOSI[] = {
|
||||||
{PA_7, SPI_1, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_NOPULL, GPIO_AF_0)},
|
{PA_7, SPI_1, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_NOPULL, GPIO_AF_0)},
|
||||||
|
@ -90,10 +90,7 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
|
||||||
SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel);
|
SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel);
|
||||||
|
|
||||||
obj->spi = (SPIName)pinmap_merge(spi_data, spi_cntl);
|
obj->spi = (SPIName)pinmap_merge(spi_data, spi_cntl);
|
||||||
|
assert(obj->spi != (SPIName)NC);
|
||||||
if (obj->spi == (SPIName)NC) {
|
|
||||||
error("SPI pinout mapping failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable SPI clock
|
// Enable SPI clock
|
||||||
if (obj->spi == SPI_1) {
|
if (obj->spi == SPI_1) {
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "analogin_api.h"
|
#include "analogin_api.h"
|
||||||
#include "wait_api.h"
|
#include "wait_api.h"
|
||||||
|
|
||||||
|
@ -32,7 +33,6 @@
|
||||||
|
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
|
|
||||||
static const PinMap PinMap_ADC[] = {
|
static const PinMap PinMap_ADC[] = {
|
||||||
{PA_0, ADC_1, STM_PIN_DATA(GPIO_Mode_AIN, 0)},
|
{PA_0, ADC_1, STM_PIN_DATA(GPIO_Mode_AIN, 0)},
|
||||||
|
@ -53,10 +53,7 @@ void analogin_init(analogin_t *obj, PinName pin) {
|
||||||
|
|
||||||
// Get the peripheral name (ADC_1, ADC_2...) from the pin and assign it to the object
|
// Get the peripheral name (ADC_1, ADC_2...) from the pin and assign it to the object
|
||||||
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
|
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
|
||||||
|
assert(obj->adc != (ADCName)NC);
|
||||||
if (obj->adc == (ADCName)NC) {
|
|
||||||
error("ADC pin mapping failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configure GPIO
|
// Configure GPIO
|
||||||
pinmap_pinout(pin, PinMap_ADC);
|
pinmap_pinout(pin, PinMap_ADC);
|
||||||
|
|
|
@ -27,13 +27,13 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "i2c_api.h"
|
#include "i2c_api.h"
|
||||||
|
|
||||||
#if DEVICE_I2C
|
#if DEVICE_I2C
|
||||||
|
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
|
|
||||||
/* Timeout values for flags and events waiting loops. These timeouts are
|
/* Timeout values for flags and events waiting loops. These timeouts are
|
||||||
not based on accurate values, they just guarantee that the application will
|
not based on accurate values, they just guarantee that the application will
|
||||||
|
@ -57,10 +57,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
|
||||||
I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
|
I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
|
||||||
|
|
||||||
obj->i2c = (I2CName)pinmap_merge(i2c_sda, i2c_scl);
|
obj->i2c = (I2CName)pinmap_merge(i2c_sda, i2c_scl);
|
||||||
|
assert(obj->i2c != (I2CName)NC);
|
||||||
if (obj->i2c == (I2CName)NC) {
|
|
||||||
error("I2C pin mapping failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable I2C clock
|
// Enable I2C clock
|
||||||
if (obj->i2c == I2C_1) {
|
if (obj->i2c == I2C_1) {
|
||||||
|
|
|
@ -27,11 +27,11 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "pwmout_api.h"
|
#include "pwmout_api.h"
|
||||||
|
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
|
|
||||||
static const PinMap PinMap_PWM[] = {
|
static const PinMap PinMap_PWM[] = {
|
||||||
// TIM2 full remap
|
// TIM2 full remap
|
||||||
|
@ -46,10 +46,7 @@ static const PinMap PinMap_PWM[] = {
|
||||||
void pwmout_init(pwmout_t* obj, PinName pin) {
|
void pwmout_init(pwmout_t* obj, PinName pin) {
|
||||||
// Get the peripheral name from the pin and assign it to the object
|
// Get the peripheral name from the pin and assign it to the object
|
||||||
obj->pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
|
obj->pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
|
||||||
|
assert(obj->pwm != (PWMName)NC);
|
||||||
if (obj->pwm == (PWMName)NC) {
|
|
||||||
error("PWM pinout mapping failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable TIM clock
|
// Enable TIM clock
|
||||||
if (obj->pwm == PWM_2) RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
|
if (obj->pwm == PWM_2) RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
|
||||||
|
|
|
@ -27,10 +27,10 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "serial_api.h"
|
#include "serial_api.h"
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
static const PinMap PinMap_UART_TX[] = {
|
static const PinMap PinMap_UART_TX[] = {
|
||||||
|
@ -80,10 +80,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
|
||||||
|
|
||||||
// Get the peripheral name (UART_1, UART_2, ...) from the pin and assign it to the object
|
// Get the peripheral name (UART_1, UART_2, ...) from the pin and assign it to the object
|
||||||
obj->uart = (UARTName)pinmap_merge(uart_tx, uart_rx);
|
obj->uart = (UARTName)pinmap_merge(uart_tx, uart_rx);
|
||||||
|
assert(obj->uart != (UARTName)NC);
|
||||||
if (obj->uart == (UARTName)NC) {
|
|
||||||
error("Serial pinout mapping failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable USART clock
|
// Enable USART clock
|
||||||
if (obj->uart == UART_1) {
|
if (obj->uart == UART_1) {
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "spi_api.h"
|
#include "spi_api.h"
|
||||||
|
|
||||||
#if DEVICE_SPI
|
#if DEVICE_SPI
|
||||||
|
@ -34,7 +35,6 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
|
|
||||||
static const PinMap PinMap_SPI_MOSI[] = {
|
static const PinMap PinMap_SPI_MOSI[] = {
|
||||||
{PA_7, SPI_1, STM_PIN_DATA(GPIO_Mode_AF_PP, 0)},
|
{PA_7, SPI_1, STM_PIN_DATA(GPIO_Mode_AF_PP, 0)},
|
||||||
|
@ -91,10 +91,7 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
|
||||||
SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel);
|
SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel);
|
||||||
|
|
||||||
obj->spi = (SPIName)pinmap_merge(spi_data, spi_cntl);
|
obj->spi = (SPIName)pinmap_merge(spi_data, spi_cntl);
|
||||||
|
assert(obj->spi != (SPIName)NC);
|
||||||
if (obj->spi == (SPIName)NC) {
|
|
||||||
error("SPI pinout mapping failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable SPI clock
|
// Enable SPI clock
|
||||||
if (obj->spi == SPI_1) {
|
if (obj->spi == SPI_1) {
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "analogin_api.h"
|
#include "analogin_api.h"
|
||||||
#include "wait_api.h"
|
#include "wait_api.h"
|
||||||
|
|
||||||
|
@ -32,7 +33,6 @@
|
||||||
|
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
|
|
||||||
static const PinMap PinMap_ADC[] = {
|
static const PinMap PinMap_ADC[] = {
|
||||||
{PA_0, ADC_1, STM_PIN_DATA(GPIO_Mode_AN, GPIO_OType_PP, GPIO_PuPd_NOPULL, 0xFF)}, // ADC_IN1
|
{PA_0, ADC_1, STM_PIN_DATA(GPIO_Mode_AN, GPIO_OType_PP, GPIO_PuPd_NOPULL, 0xFF)}, // ADC_IN1
|
||||||
|
@ -63,10 +63,7 @@ void analogin_init(analogin_t *obj, PinName pin) {
|
||||||
|
|
||||||
// Get the peripheral name from the pin and assign it to the object
|
// Get the peripheral name from the pin and assign it to the object
|
||||||
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
|
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
|
||||||
|
assert(obj->adc != (ADCName)NC);
|
||||||
if (obj->adc == (ADCName)NC) {
|
|
||||||
error("ADC pin mapping failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configure GPIO
|
// Configure GPIO
|
||||||
pinmap_pinout(pin, PinMap_ADC);
|
pinmap_pinout(pin, PinMap_ADC);
|
||||||
|
|
|
@ -27,13 +27,13 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "i2c_api.h"
|
#include "i2c_api.h"
|
||||||
|
|
||||||
#if DEVICE_I2C
|
#if DEVICE_I2C
|
||||||
|
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
|
|
||||||
/* Timeout values for flags and events waiting loops. These timeouts are
|
/* Timeout values for flags and events waiting loops. These timeouts are
|
||||||
not based on accurate values, they just guarantee that the application will
|
not based on accurate values, they just guarantee that the application will
|
||||||
|
@ -68,10 +68,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
|
||||||
I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
|
I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
|
||||||
|
|
||||||
obj->i2c = (I2CName)pinmap_merge(i2c_sda, i2c_scl);
|
obj->i2c = (I2CName)pinmap_merge(i2c_sda, i2c_scl);
|
||||||
|
assert(obj->i2c != (I2CName)NC);
|
||||||
if (obj->i2c == (I2CName)NC) {
|
|
||||||
error("I2C pin mapping failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable I2C clock
|
// Enable I2C clock
|
||||||
if (obj->i2c == I2C_1) {
|
if (obj->i2c == I2C_1) {
|
||||||
|
@ -98,6 +95,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void i2c_frequency(i2c_t *obj, int hz) {
|
void i2c_frequency(i2c_t *obj, int hz) {
|
||||||
|
assert((hz == 100000) || (hz == 200000) || (hz == 400000) || (hz == 1000000));
|
||||||
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
|
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
|
||||||
I2C_InitTypeDef I2C_InitStructure;
|
I2C_InitTypeDef I2C_InitStructure;
|
||||||
uint32_t tim;
|
uint32_t tim;
|
||||||
|
@ -140,7 +138,6 @@ void i2c_frequency(i2c_t *obj, int hz) {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
error("Only 100kHz, 200kHz, 400kHz and 1MHz I2C frequencies are supported.");
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,11 +27,11 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "pwmout_api.h"
|
#include "pwmout_api.h"
|
||||||
|
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
|
|
||||||
// TIM2 cannot be used because already used by the us_ticker
|
// TIM2 cannot be used because already used by the us_ticker
|
||||||
static const PinMap PinMap_PWM[] = {
|
static const PinMap PinMap_PWM[] = {
|
||||||
|
@ -88,10 +88,7 @@ static const PinMap PinMap_PWM[] = {
|
||||||
void pwmout_init(pwmout_t* obj, PinName pin) {
|
void pwmout_init(pwmout_t* obj, PinName pin) {
|
||||||
// Get the peripheral name from the pin and assign it to the object
|
// Get the peripheral name from the pin and assign it to the object
|
||||||
obj->pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
|
obj->pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
|
||||||
|
assert(obj->pwm != (PWMName)NC);
|
||||||
if (obj->pwm == (PWMName)NC) {
|
|
||||||
error("PWM pinout mapping failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable TIM clock
|
// Enable TIM clock
|
||||||
if (obj->pwm == PWM_1) RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
|
if (obj->pwm == PWM_1) RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
|
||||||
|
|
|
@ -27,10 +27,10 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "serial_api.h"
|
#include "serial_api.h"
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
static const PinMap PinMap_UART_TX[] = {
|
static const PinMap PinMap_UART_TX[] = {
|
||||||
|
@ -92,10 +92,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
|
||||||
|
|
||||||
// Get the peripheral name from the pin and assign it to the object
|
// Get the peripheral name from the pin and assign it to the object
|
||||||
obj->uart = (UARTName)pinmap_merge(uart_tx, uart_rx);
|
obj->uart = (UARTName)pinmap_merge(uart_tx, uart_rx);
|
||||||
|
assert(obj->uart != (UARTName)NC);
|
||||||
if (obj->uart == (UARTName)NC) {
|
|
||||||
error("Serial pinout mapping failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable USART clock
|
// Enable USART clock
|
||||||
if (obj->uart == UART_1) {
|
if (obj->uart == UART_1) {
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "spi_api.h"
|
#include "spi_api.h"
|
||||||
|
|
||||||
#if DEVICE_SPI
|
#if DEVICE_SPI
|
||||||
|
@ -34,7 +35,6 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
|
|
||||||
static const PinMap PinMap_SPI_MOSI[] = {
|
static const PinMap PinMap_SPI_MOSI[] = {
|
||||||
{PA_11, SPI_2, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_DOWN, GPIO_AF_5)},
|
{PA_11, SPI_2, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_DOWN, GPIO_AF_5)},
|
||||||
|
@ -101,10 +101,7 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
|
||||||
SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel);
|
SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel);
|
||||||
|
|
||||||
obj->spi = (SPIName)pinmap_merge(spi_data, spi_cntl);
|
obj->spi = (SPIName)pinmap_merge(spi_data, spi_cntl);
|
||||||
|
assert(obj->spi != (SPIName)NC);
|
||||||
if (obj->spi == (SPIName)NC) {
|
|
||||||
error("SPI pinout mapping failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable SPI clock
|
// Enable SPI clock
|
||||||
if (obj->spi == SPI_2) {
|
if (obj->spi == SPI_2) {
|
||||||
|
|
|
@ -32,7 +32,6 @@
|
||||||
|
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
#include "stm32f4xx_hal.h"
|
#include "stm32f4xx_hal.h"
|
||||||
|
|
||||||
static const PinMap PinMap_ADC[] = {
|
static const PinMap PinMap_ADC[] = {
|
||||||
|
@ -62,10 +61,7 @@ int adc_inited = 0;
|
||||||
void analogin_init(analogin_t *obj, PinName pin) {
|
void analogin_init(analogin_t *obj, PinName pin) {
|
||||||
// Get the peripheral name (ADC_1, ADC_2...) from the pin and assign it to the object
|
// Get the peripheral name (ADC_1, ADC_2...) from the pin and assign it to the object
|
||||||
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
|
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
|
||||||
|
assert(obj->adc != (ADCName)NC);
|
||||||
if (obj->adc == (ADCName)NC) {
|
|
||||||
error("ADC error: pinout mapping failed.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configure GPIO
|
// Configure GPIO
|
||||||
pinmap_pinout(pin, PinMap_ADC);
|
pinmap_pinout(pin, PinMap_ADC);
|
||||||
|
|
|
@ -27,13 +27,13 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "i2c_api.h"
|
#include "i2c_api.h"
|
||||||
|
|
||||||
#if DEVICE_I2C
|
#if DEVICE_I2C
|
||||||
|
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
#include "stm32f4xx_hal.h"
|
#include "stm32f4xx_hal.h"
|
||||||
|
|
||||||
/* Timeout values for flags and events waiting loops. These timeouts are
|
/* Timeout values for flags and events waiting loops. These timeouts are
|
||||||
|
@ -71,10 +71,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
|
||||||
I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
|
I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
|
||||||
|
|
||||||
obj->i2c = (I2CName)pinmap_merge(i2c_sda, i2c_scl);
|
obj->i2c = (I2CName)pinmap_merge(i2c_sda, i2c_scl);
|
||||||
|
assert(obj->i2c != (I2CName)NC);
|
||||||
if (obj->i2c == (I2CName)NC) {
|
|
||||||
error("I2C error: pinout mapping failed.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable I2C clock
|
// Enable I2C clock
|
||||||
if (obj->i2c == I2C_1) {
|
if (obj->i2c == I2C_1) {
|
||||||
|
@ -101,6 +98,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void i2c_frequency(i2c_t *obj, int hz) {
|
void i2c_frequency(i2c_t *obj, int hz) {
|
||||||
|
assert((hz != 0) && (hz <= 400000));
|
||||||
I2cHandle.Instance = (I2C_TypeDef *)(obj->i2c);
|
I2cHandle.Instance = (I2C_TypeDef *)(obj->i2c);
|
||||||
|
|
||||||
if ((hz != 0) && (hz <= 400000)) {
|
if ((hz != 0) && (hz <= 400000)) {
|
||||||
|
@ -115,9 +113,6 @@ void i2c_frequency(i2c_t *obj, int hz) {
|
||||||
I2cHandle.Init.OwnAddress2 = 0;
|
I2cHandle.Init.OwnAddress2 = 0;
|
||||||
HAL_I2C_Init(&I2cHandle);
|
HAL_I2C_Init(&I2cHandle);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
error("I2C error: frequency setting failed (max 400kHz).");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int i2c_start(i2c_t *obj) {
|
inline int i2c_start(i2c_t *obj) {
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "pwmout_api.h"
|
#include "pwmout_api.h"
|
||||||
|
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
|
@ -87,10 +88,7 @@ static TIM_HandleTypeDef TimHandle;
|
||||||
void pwmout_init(pwmout_t* obj, PinName pin) {
|
void pwmout_init(pwmout_t* obj, PinName pin) {
|
||||||
// Get the peripheral name from the pin and assign it to the object
|
// Get the peripheral name from the pin and assign it to the object
|
||||||
obj->pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
|
obj->pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
|
||||||
|
assert(obj->pwm != (PWMName)NC);
|
||||||
if (obj->pwm == (PWMName)NC) {
|
|
||||||
error("PWM error: pinout mapping failed.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable TIM clock
|
// Enable TIM clock
|
||||||
if (obj->pwm == PWM_1) __TIM1_CLK_ENABLE();
|
if (obj->pwm == PWM_1) __TIM1_CLK_ENABLE();
|
||||||
|
|
|
@ -30,7 +30,6 @@
|
||||||
#include "serial_api.h"
|
#include "serial_api.h"
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "stm32f4xx_hal.h"
|
#include "stm32f4xx_hal.h"
|
||||||
|
|
||||||
|
@ -83,10 +82,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
|
||||||
|
|
||||||
// Get the peripheral name (UART_1, UART_2, ...) from the pin and assign it to the object
|
// Get the peripheral name (UART_1, UART_2, ...) from the pin and assign it to the object
|
||||||
obj->uart = (UARTName)pinmap_merge(uart_tx, uart_rx);
|
obj->uart = (UARTName)pinmap_merge(uart_tx, uart_rx);
|
||||||
|
assert(obj->uart != (UARTName)NC);
|
||||||
if (obj->uart == (UARTName)NC) {
|
|
||||||
error("Serial error: pinout mapping failed.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable USART clock
|
// Enable USART clock
|
||||||
if (obj->uart == UART_1) {
|
if (obj->uart == UART_1) {
|
||||||
|
|
|
@ -34,7 +34,6 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
#include "stm32f4xx_hal.h"
|
#include "stm32f4xx_hal.h"
|
||||||
|
|
||||||
static const PinMap PinMap_SPI_MOSI[] = {
|
static const PinMap PinMap_SPI_MOSI[] = {
|
||||||
|
@ -112,10 +111,7 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
|
||||||
SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel);
|
SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel);
|
||||||
|
|
||||||
obj->spi = (SPIName)pinmap_merge(spi_data, spi_cntl);
|
obj->spi = (SPIName)pinmap_merge(spi_data, spi_cntl);
|
||||||
|
assert(obj->spi != (SPIName)NC);
|
||||||
if (obj->spi == (SPIName)NC) {
|
|
||||||
error("SPI error: pinout mapping failed.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable SPI clock
|
// Enable SPI clock
|
||||||
if (obj->spi == SPI_1) {
|
if (obj->spi == SPI_1) {
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "analogin_api.h"
|
#include "analogin_api.h"
|
||||||
|
|
||||||
#if DEVICE_ANALOGIN
|
#if DEVICE_ANALOGIN
|
||||||
|
@ -63,10 +64,7 @@ void analogin_init(analogin_t *obj, PinName pin) {
|
||||||
|
|
||||||
// Get the peripheral name (ADC_1, ADC_2...) from the pin and assign it to the object
|
// Get the peripheral name (ADC_1, ADC_2...) from the pin and assign it to the object
|
||||||
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
|
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
|
||||||
|
assert(obj->adc != (ADCName)NC);
|
||||||
if (obj->adc == (ADCName)NC) {
|
|
||||||
error("ADC pin mapping failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configure GPIO
|
// Configure GPIO
|
||||||
pinmap_pinout(pin, PinMap_ADC);
|
pinmap_pinout(pin, PinMap_ADC);
|
||||||
|
|
|
@ -64,7 +64,7 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void gpio_dir(gpio_t *obj, PinDirection direction) {
|
void gpio_dir(gpio_t *obj, PinDirection direction) {
|
||||||
assert(pin != (PinName)NC);
|
assert(obj->pin != (PinName)NC);
|
||||||
if (direction == PIN_OUTPUT) {
|
if (direction == PIN_OUTPUT) {
|
||||||
pin_function(obj->pin, STM_PIN_DATA(GPIO_Mode_OUT, GPIO_OType_PP, GPIO_PuPd_NOPULL, 0xFF));
|
pin_function(obj->pin, STM_PIN_DATA(GPIO_Mode_OUT, GPIO_OType_PP, GPIO_PuPd_NOPULL, 0xFF));
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,13 +27,13 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "i2c_api.h"
|
#include "i2c_api.h"
|
||||||
|
|
||||||
#if DEVICE_I2C
|
#if DEVICE_I2C
|
||||||
|
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
|
|
||||||
/* Timeout values for flags and events waiting loops. These timeouts are
|
/* Timeout values for flags and events waiting loops. These timeouts are
|
||||||
not based on accurate values, they just guarantee that the application will
|
not based on accurate values, they just guarantee that the application will
|
||||||
|
@ -61,10 +61,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
|
||||||
I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
|
I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
|
||||||
|
|
||||||
obj->i2c = (I2CName)pinmap_merge(i2c_sda, i2c_scl);
|
obj->i2c = (I2CName)pinmap_merge(i2c_sda, i2c_scl);
|
||||||
|
assert(obj->i2c != (I2CName)NC);
|
||||||
if (obj->i2c == (I2CName)NC) {
|
|
||||||
error("I2C pin mapping failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable I2C clock
|
// Enable I2C clock
|
||||||
if (obj->i2c == I2C_1) {
|
if (obj->i2c == I2C_1) {
|
||||||
|
@ -89,6 +86,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void i2c_frequency(i2c_t *obj, int hz) {
|
void i2c_frequency(i2c_t *obj, int hz) {
|
||||||
|
assert((hz == 100000) || (hz == 200000) || (hz == 400000) || (hz == 1000000));
|
||||||
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
|
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
|
||||||
I2C_InitTypeDef I2C_InitStructure;
|
I2C_InitTypeDef I2C_InitStructure;
|
||||||
uint32_t tim = 0;
|
uint32_t tim = 0;
|
||||||
|
@ -131,7 +129,6 @@ void i2c_frequency(i2c_t *obj, int hz) {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
error("Only 100kHz, 200kHz, 400kHz and 1MHz I2C frequencies are supported.");
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,13 +27,13 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "pwmout_api.h"
|
#include "pwmout_api.h"
|
||||||
|
|
||||||
#if DEVICE_PWMOUT
|
#if DEVICE_PWMOUT
|
||||||
|
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
|
|
||||||
// TIM1 cannot be used because already used by the us_ticker
|
// TIM1 cannot be used because already used by the us_ticker
|
||||||
static const PinMap PinMap_PWM[] = {
|
static const PinMap PinMap_PWM[] = {
|
||||||
|
@ -65,10 +65,7 @@ static const PinMap PinMap_PWM[] = {
|
||||||
void pwmout_init(pwmout_t* obj, PinName pin) {
|
void pwmout_init(pwmout_t* obj, PinName pin) {
|
||||||
// Get the peripheral name from the pin and assign it to the object
|
// Get the peripheral name from the pin and assign it to the object
|
||||||
obj->pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
|
obj->pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
|
||||||
|
assert(obj->pwm != (PWMName)NC);
|
||||||
if (obj->pwm == (PWMName)NC) {
|
|
||||||
error("PWM pinout mapping failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable TIM clock
|
// Enable TIM clock
|
||||||
if (obj->pwm == TIM_3) RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
|
if (obj->pwm == TIM_3) RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
|
||||||
|
|
|
@ -27,13 +27,13 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "serial_api.h"
|
#include "serial_api.h"
|
||||||
|
|
||||||
#if DEVICE_SERIAL
|
#if DEVICE_SERIAL
|
||||||
|
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
static const PinMap PinMap_UART_TX[] = {
|
static const PinMap PinMap_UART_TX[] = {
|
||||||
|
@ -84,10 +84,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
|
||||||
|
|
||||||
// Get the peripheral name (UART_1, UART_2, ...) from the pin and assign it to the object
|
// Get the peripheral name (UART_1, UART_2, ...) from the pin and assign it to the object
|
||||||
obj->uart = (UARTName)pinmap_merge(uart_tx, uart_rx);
|
obj->uart = (UARTName)pinmap_merge(uart_tx, uart_rx);
|
||||||
|
assert(obj->uart != (UARTName)NC);
|
||||||
if (obj->uart == (UARTName)NC) {
|
|
||||||
error("Serial pinout mapping failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable USART clock
|
// Enable USART clock
|
||||||
if (obj->uart == UART_1) {
|
if (obj->uart == UART_1) {
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "spi_api.h"
|
#include "spi_api.h"
|
||||||
|
|
||||||
#if DEVICE_SPI
|
#if DEVICE_SPI
|
||||||
|
@ -34,7 +35,6 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
|
|
||||||
static const PinMap PinMap_SPI_MOSI[] = {
|
static const PinMap PinMap_SPI_MOSI[] = {
|
||||||
{PA_7, SPI_1, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_NOPULL, GPIO_AF_0)},
|
{PA_7, SPI_1, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_NOPULL, GPIO_AF_0)},
|
||||||
|
@ -98,10 +98,7 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
|
||||||
SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel);
|
SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel);
|
||||||
|
|
||||||
obj->spi = (SPIName)pinmap_merge(spi_data, spi_cntl);
|
obj->spi = (SPIName)pinmap_merge(spi_data, spi_cntl);
|
||||||
|
assert(obj->spi != (SPIName)NC);
|
||||||
if (obj->spi == (SPIName)NC) {
|
|
||||||
error("SPI pinout mapping failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable SPI clock
|
// Enable SPI clock
|
||||||
if (obj->spi == SPI_1) {
|
if (obj->spi == SPI_1) {
|
||||||
|
|
|
@ -25,13 +25,13 @@
|
||||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "analogin_api.h"
|
#include "analogin_api.h"
|
||||||
|
|
||||||
#if DEVICE_ANALOGIN
|
#if DEVICE_ANALOGIN
|
||||||
|
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
#include "wait_api.h"
|
#include "wait_api.h"
|
||||||
|
|
||||||
static const PinMap PinMap_ADC[] = {
|
static const PinMap PinMap_ADC[] = {
|
||||||
|
@ -62,10 +62,7 @@ void analogin_init(analogin_t *obj, PinName pin) {
|
||||||
|
|
||||||
// Get the peripheral name from the pin and assign it to the object
|
// Get the peripheral name from the pin and assign it to the object
|
||||||
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
|
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
|
||||||
|
assert(obj->adc != (ADCName)NC);
|
||||||
if (obj->adc == (ADCName)NC) {
|
|
||||||
error("ADC pin mapping failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configure GPIO
|
// Configure GPIO
|
||||||
pinmap_pinout(pin, PinMap_ADC);
|
pinmap_pinout(pin, PinMap_ADC);
|
||||||
|
|
|
@ -27,13 +27,13 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "i2c_api.h"
|
#include "i2c_api.h"
|
||||||
|
|
||||||
#if DEVICE_I2C
|
#if DEVICE_I2C
|
||||||
|
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
|
|
||||||
/* Timeout values for flags and events waiting loops. These timeouts are
|
/* Timeout values for flags and events waiting loops. These timeouts are
|
||||||
not based on accurate values, they just guarantee that the application will
|
not based on accurate values, they just guarantee that the application will
|
||||||
|
@ -61,10 +61,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
|
||||||
I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
|
I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
|
||||||
|
|
||||||
obj->i2c = (I2CName)pinmap_merge(i2c_sda, i2c_scl);
|
obj->i2c = (I2CName)pinmap_merge(i2c_sda, i2c_scl);
|
||||||
|
assert(obj->i2c != (I2CName)NC);
|
||||||
if (obj->i2c == (I2CName)NC) {
|
|
||||||
error("I2C pin mapping failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable I2C clock
|
// Enable I2C clock
|
||||||
if (obj->i2c == I2C_1) {
|
if (obj->i2c == I2C_1) {
|
||||||
|
|
|
@ -27,13 +27,13 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "pwmout_api.h"
|
#include "pwmout_api.h"
|
||||||
|
|
||||||
#if DEVICE_PWMOUT
|
#if DEVICE_PWMOUT
|
||||||
|
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
|
|
||||||
// TIM4 cannot be used because already used by the us_ticker
|
// TIM4 cannot be used because already used by the us_ticker
|
||||||
static const PinMap PinMap_PWM[] = {
|
static const PinMap PinMap_PWM[] = {
|
||||||
|
@ -76,10 +76,7 @@ static const PinMap PinMap_PWM[] = {
|
||||||
void pwmout_init(pwmout_t* obj, PinName pin) {
|
void pwmout_init(pwmout_t* obj, PinName pin) {
|
||||||
// Get the peripheral name from the pin and assign it to the object
|
// Get the peripheral name from the pin and assign it to the object
|
||||||
obj->pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
|
obj->pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
|
||||||
|
assert(obj->pwm != (PWMName)NC);
|
||||||
if (obj->pwm == (PWMName)NC) {
|
|
||||||
error("PWM pinout mapping failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable TIM clock
|
// Enable TIM clock
|
||||||
if (obj->pwm == PWM_1) RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
|
if (obj->pwm == PWM_1) RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
|
||||||
|
|
|
@ -27,13 +27,13 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "serial_api.h"
|
#include "serial_api.h"
|
||||||
|
|
||||||
#if DEVICE_SERIAL
|
#if DEVICE_SERIAL
|
||||||
|
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
static const PinMap PinMap_UART_TX[] = {
|
static const PinMap PinMap_UART_TX[] = {
|
||||||
|
@ -87,10 +87,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
|
||||||
|
|
||||||
// Get the peripheral name (UART_1, UART_2, ...) from the pin and assign it to the object
|
// Get the peripheral name (UART_1, UART_2, ...) from the pin and assign it to the object
|
||||||
obj->uart = (UARTName)pinmap_merge(uart_tx, uart_rx);
|
obj->uart = (UARTName)pinmap_merge(uart_tx, uart_rx);
|
||||||
|
assert(obj->uart != (UARTName)NC);
|
||||||
if (obj->uart == (UARTName)NC) {
|
|
||||||
error("Serial pinout mapping failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable USART clock
|
// Enable USART clock
|
||||||
if (obj->uart == UART_1) {
|
if (obj->uart == UART_1) {
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "spi_api.h"
|
#include "spi_api.h"
|
||||||
|
|
||||||
#if DEVICE_SPI
|
#if DEVICE_SPI
|
||||||
|
@ -34,7 +35,6 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
|
|
||||||
static const PinMap PinMap_SPI_MOSI[] = {
|
static const PinMap PinMap_SPI_MOSI[] = {
|
||||||
{PA_7, SPI_1, STM_PIN_DATA(GPIO_Mode_AF_PP, 0)},
|
{PA_7, SPI_1, STM_PIN_DATA(GPIO_Mode_AF_PP, 0)},
|
||||||
|
@ -95,10 +95,7 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
|
||||||
SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel);
|
SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel);
|
||||||
|
|
||||||
obj->spi = (SPIName)pinmap_merge(spi_data, spi_cntl);
|
obj->spi = (SPIName)pinmap_merge(spi_data, spi_cntl);
|
||||||
|
assert(obj->spi != (SPIName)NC);
|
||||||
if (obj->spi == (SPIName)NC) {
|
|
||||||
error("SPI pinout mapping failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable SPI clock
|
// Enable SPI clock
|
||||||
if (obj->spi == SPI_1) {
|
if (obj->spi == SPI_1) {
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "analogin_api.h"
|
#include "analogin_api.h"
|
||||||
|
|
||||||
#if DEVICE_ANALOGIN
|
#if DEVICE_ANALOGIN
|
||||||
|
@ -32,7 +33,6 @@
|
||||||
#include "wait_api.h"
|
#include "wait_api.h"
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
|
|
||||||
static const PinMap PinMap_ADC[] = {
|
static const PinMap PinMap_ADC[] = {
|
||||||
{PA_0, ADC_1, STM_PIN_DATA(GPIO_Mode_AN, GPIO_OType_PP, GPIO_PuPd_NOPULL, 0xFF)}, // ADC_IN1
|
{PA_0, ADC_1, STM_PIN_DATA(GPIO_Mode_AN, GPIO_OType_PP, GPIO_PuPd_NOPULL, 0xFF)}, // ADC_IN1
|
||||||
|
@ -63,10 +63,7 @@ void analogin_init(analogin_t *obj, PinName pin) {
|
||||||
|
|
||||||
// Get the peripheral name from the pin and assign it to the object
|
// Get the peripheral name from the pin and assign it to the object
|
||||||
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
|
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
|
||||||
|
assert(obj->adc != (ADCName)NC);
|
||||||
if (obj->adc == (ADCName)NC) {
|
|
||||||
error("ADC pin mapping failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configure GPIO
|
// Configure GPIO
|
||||||
pinmap_pinout(pin, PinMap_ADC);
|
pinmap_pinout(pin, PinMap_ADC);
|
||||||
|
|
|
@ -25,13 +25,13 @@
|
||||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "analogout_api.h"
|
#include "analogout_api.h"
|
||||||
|
|
||||||
#if DEVICE_ANALOGOUT
|
#if DEVICE_ANALOGOUT
|
||||||
|
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
|
|
||||||
#define DAC_RANGE (0xFFF) // 12 bits
|
#define DAC_RANGE (0xFFF) // 12 bits
|
||||||
|
|
||||||
|
@ -46,10 +46,7 @@ void analogout_init(dac_t *obj, PinName pin) {
|
||||||
|
|
||||||
// Get the peripheral name (DAC_1, ...) from the pin and assign it to the object
|
// Get the peripheral name (DAC_1, ...) from the pin and assign it to the object
|
||||||
obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC);
|
obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC);
|
||||||
|
assert(obj->dac != (DACName)NC);
|
||||||
if (obj->dac == (DACName)NC) {
|
|
||||||
error("DAC pin mapping failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
dac = (DAC_TypeDef *)(obj->dac);
|
dac = (DAC_TypeDef *)(obj->dac);
|
||||||
|
|
||||||
|
|
|
@ -27,13 +27,13 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "i2c_api.h"
|
#include "i2c_api.h"
|
||||||
|
|
||||||
#if DEVICE_I2C
|
#if DEVICE_I2C
|
||||||
|
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
|
|
||||||
/* Timeout values for flags and events waiting loops. These timeouts are
|
/* Timeout values for flags and events waiting loops. These timeouts are
|
||||||
not based on accurate values, they just guarantee that the application will
|
not based on accurate values, they just guarantee that the application will
|
||||||
|
@ -68,10 +68,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
|
||||||
I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
|
I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
|
||||||
|
|
||||||
obj->i2c = (I2CName)pinmap_merge(i2c_sda, i2c_scl);
|
obj->i2c = (I2CName)pinmap_merge(i2c_sda, i2c_scl);
|
||||||
|
assert(obj->i2c != (I2CName)NC);
|
||||||
if (obj->i2c == (I2CName)NC) {
|
|
||||||
error("I2C pin mapping failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable I2C clock
|
// Enable I2C clock
|
||||||
if (obj->i2c == I2C_1) {
|
if (obj->i2c == I2C_1) {
|
||||||
|
@ -98,6 +95,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void i2c_frequency(i2c_t *obj, int hz) {
|
void i2c_frequency(i2c_t *obj, int hz) {
|
||||||
|
assert((hz == 100000) || (hz == 200000) || (hz == 400000) || (hz == 1000000));
|
||||||
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
|
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
|
||||||
I2C_InitTypeDef I2C_InitStructure;
|
I2C_InitTypeDef I2C_InitStructure;
|
||||||
uint32_t tim = 0;
|
uint32_t tim = 0;
|
||||||
|
@ -140,7 +138,6 @@ void i2c_frequency(i2c_t *obj, int hz) {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
error("Only 100kHz, 200kHz, 400kHz and 1MHz I2C frequencies are supported.");
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,13 +27,13 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "serial_api.h"
|
#include "serial_api.h"
|
||||||
|
|
||||||
#if DEVICE_SERIAL
|
#if DEVICE_SERIAL
|
||||||
|
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
static const PinMap PinMap_UART_TX[] = {
|
static const PinMap PinMap_UART_TX[] = {
|
||||||
|
@ -95,10 +95,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
|
||||||
|
|
||||||
// Get the peripheral name from the pin and assign it to the object
|
// Get the peripheral name from the pin and assign it to the object
|
||||||
obj->uart = (UARTName)pinmap_merge(uart_tx, uart_rx);
|
obj->uart = (UARTName)pinmap_merge(uart_tx, uart_rx);
|
||||||
|
assert(obj->uart != (UARTName)NC);
|
||||||
if (obj->uart == (UARTName)NC) {
|
|
||||||
error("Serial pinout mapping failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable USART clock
|
// Enable USART clock
|
||||||
if (obj->uart == UART_1) {
|
if (obj->uart == UART_1) {
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "spi_api.h"
|
#include "spi_api.h"
|
||||||
|
|
||||||
#if DEVICE_SPI
|
#if DEVICE_SPI
|
||||||
|
@ -34,7 +35,6 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
|
|
||||||
static const PinMap PinMap_SPI_MOSI[] = {
|
static const PinMap PinMap_SPI_MOSI[] = {
|
||||||
{PA_11, SPI_2, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_DOWN, GPIO_AF_5)},
|
{PA_11, SPI_2, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_DOWN, GPIO_AF_5)},
|
||||||
|
@ -101,10 +101,7 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
|
||||||
SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel);
|
SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel);
|
||||||
|
|
||||||
obj->spi = (SPIName)pinmap_merge(spi_data, spi_cntl);
|
obj->spi = (SPIName)pinmap_merge(spi_data, spi_cntl);
|
||||||
|
assert(obj->spi != (SPIName)NC);
|
||||||
if (obj->spi == (SPIName)NC) {
|
|
||||||
error("SPI pinout mapping failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable SPI clock
|
// Enable SPI clock
|
||||||
if (obj->spi == SPI_2) {
|
if (obj->spi == SPI_2) {
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "analogin_api.h"
|
#include "analogin_api.h"
|
||||||
|
|
||||||
#if DEVICE_ANALOGIN
|
#if DEVICE_ANALOGIN
|
||||||
|
@ -32,7 +33,6 @@
|
||||||
#include "wait_api.h"
|
#include "wait_api.h"
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
|
|
||||||
static const PinMap PinMap_ADC[] = {
|
static const PinMap PinMap_ADC[] = {
|
||||||
{PA_0, ADC_1, STM_PIN_DATA(STM_MODE_ANALOG, GPIO_NOPULL, 0)}, // ADC1_IN0
|
{PA_0, ADC_1, STM_PIN_DATA(STM_MODE_ANALOG, GPIO_NOPULL, 0)}, // ADC1_IN0
|
||||||
|
@ -61,10 +61,7 @@ int adc_inited = 0;
|
||||||
void analogin_init(analogin_t *obj, PinName pin) {
|
void analogin_init(analogin_t *obj, PinName pin) {
|
||||||
// Get the peripheral name from the pin and assign it to the object
|
// Get the peripheral name from the pin and assign it to the object
|
||||||
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
|
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
|
||||||
|
assert(obj->adc != (ADCName)NC);
|
||||||
if (obj->adc == (ADCName)NC) {
|
|
||||||
error("ADC error: pinout mapping failed.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configure GPIO
|
// Configure GPIO
|
||||||
pinmap_pinout(pin, PinMap_ADC);
|
pinmap_pinout(pin, PinMap_ADC);
|
||||||
|
|
|
@ -27,13 +27,13 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "i2c_api.h"
|
#include "i2c_api.h"
|
||||||
|
|
||||||
#if DEVICE_I2C
|
#if DEVICE_I2C
|
||||||
|
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
|
|
||||||
/* Timeout values for flags and events waiting loops. These timeouts are
|
/* Timeout values for flags and events waiting loops. These timeouts are
|
||||||
not based on accurate values, they just guarantee that the application will
|
not based on accurate values, they just guarantee that the application will
|
||||||
|
@ -66,10 +66,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
|
||||||
I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
|
I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
|
||||||
|
|
||||||
obj->i2c = (I2CName)pinmap_merge(i2c_sda, i2c_scl);
|
obj->i2c = (I2CName)pinmap_merge(i2c_sda, i2c_scl);
|
||||||
|
assert(obj->i2c != (I2CName)NC);
|
||||||
if (obj->i2c == (I2CName)NC) {
|
|
||||||
error("I2C error: pinout mapping failed.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable I2C clock
|
// Enable I2C clock
|
||||||
if (obj->i2c == I2C_1) {
|
if (obj->i2c == I2C_1) {
|
||||||
|
@ -99,6 +96,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void i2c_frequency(i2c_t *obj, int hz) {
|
void i2c_frequency(i2c_t *obj, int hz) {
|
||||||
|
assert((hz != 0) && (hz <= 400000));
|
||||||
I2cHandle.Instance = (I2C_TypeDef *)(obj->i2c);
|
I2cHandle.Instance = (I2C_TypeDef *)(obj->i2c);
|
||||||
|
|
||||||
if ((hz != 0) && (hz <= 400000)) {
|
if ((hz != 0) && (hz <= 400000)) {
|
||||||
|
@ -116,8 +114,6 @@ void i2c_frequency(i2c_t *obj, int hz) {
|
||||||
/* Enable Address Acknowledge */
|
/* Enable Address Acknowledge */
|
||||||
I2cHandle.Instance->CR1 |= I2C_CR1_ACK;
|
I2cHandle.Instance->CR1 |= I2C_CR1_ACK;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
error("I2C error: frequency setting failed (max 400kHz).");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,13 +27,13 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "serial_api.h"
|
#include "serial_api.h"
|
||||||
|
|
||||||
#if DEVICE_SERIAL
|
#if DEVICE_SERIAL
|
||||||
|
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
static const PinMap PinMap_UART_TX[] = {
|
static const PinMap PinMap_UART_TX[] = {
|
||||||
|
@ -85,10 +85,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
|
||||||
|
|
||||||
// Get the peripheral name (UART_1, UART_2, ...) from the pin and assign it to the object
|
// Get the peripheral name (UART_1, UART_2, ...) from the pin and assign it to the object
|
||||||
obj->uart = (UARTName)pinmap_merge(uart_tx, uart_rx);
|
obj->uart = (UARTName)pinmap_merge(uart_tx, uart_rx);
|
||||||
|
assert(obj->uart != (UARTName)NC);
|
||||||
if (obj->uart == (UARTName)NC) {
|
|
||||||
error("Serial error: pinout mapping failed.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable USART clock
|
// Enable USART clock
|
||||||
if (obj->uart == UART_1) {
|
if (obj->uart == UART_1) {
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "spi_api.h"
|
#include "spi_api.h"
|
||||||
|
|
||||||
#if DEVICE_SPI
|
#if DEVICE_SPI
|
||||||
|
@ -34,7 +35,6 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
|
|
||||||
static const PinMap PinMap_SPI_MOSI[] = {
|
static const PinMap PinMap_SPI_MOSI[] = {
|
||||||
{PA_7, SPI_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)},
|
{PA_7, SPI_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)},
|
||||||
|
@ -111,10 +111,7 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
|
||||||
SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel);
|
SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel);
|
||||||
|
|
||||||
obj->spi = (SPIName)pinmap_merge(spi_data, spi_cntl);
|
obj->spi = (SPIName)pinmap_merge(spi_data, spi_cntl);
|
||||||
|
assert(obj->spi != (SPIName)NC);
|
||||||
if (obj->spi == (SPIName)NC) {
|
|
||||||
error("SPI error: pinout mapping failed.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable SPI clock
|
// Enable SPI clock
|
||||||
if (obj->spi == SPI_1) {
|
if (obj->spi == SPI_1) {
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "analogin_api.h"
|
#include "analogin_api.h"
|
||||||
|
|
||||||
#if DEVICE_ANALOGIN
|
#if DEVICE_ANALOGIN
|
||||||
|
@ -32,7 +33,6 @@
|
||||||
#include "wait_api.h"
|
#include "wait_api.h"
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
|
|
||||||
static const PinMap PinMap_ADC[] = {
|
static const PinMap PinMap_ADC[] = {
|
||||||
{PA_0, ADC_1, STM_PIN_DATA(STM_MODE_ANALOG, GPIO_NOPULL, 0)}, // ADC1_IN0
|
{PA_0, ADC_1, STM_PIN_DATA(STM_MODE_ANALOG, GPIO_NOPULL, 0)}, // ADC1_IN0
|
||||||
|
@ -61,10 +61,7 @@ int adc_inited = 0;
|
||||||
void analogin_init(analogin_t *obj, PinName pin) {
|
void analogin_init(analogin_t *obj, PinName pin) {
|
||||||
// Get the peripheral name from the pin and assign it to the object
|
// Get the peripheral name from the pin and assign it to the object
|
||||||
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
|
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
|
||||||
|
assert(obj->adc != (ADCName)NC);
|
||||||
if (obj->adc == (ADCName)NC) {
|
|
||||||
error("ADC error: pinout mapping failed.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configure GPIO
|
// Configure GPIO
|
||||||
pinmap_pinout(pin, PinMap_ADC);
|
pinmap_pinout(pin, PinMap_ADC);
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "analogout_api.h"
|
#include "analogout_api.h"
|
||||||
|
|
||||||
#if DEVICE_ANALOGOUT
|
#if DEVICE_ANALOGOUT
|
||||||
|
@ -49,10 +50,7 @@ void analogout_init(dac_t *obj, PinName pin) {
|
||||||
|
|
||||||
// Get the peripheral name (DAC_1, ...) from the pin and assign it to the object
|
// Get the peripheral name (DAC_1, ...) from the pin and assign it to the object
|
||||||
obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC);
|
obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC);
|
||||||
|
assert(obj->dac != (DACName)NC);
|
||||||
if (obj->dac == (DACName)NC) {
|
|
||||||
error("DAC pin mapping failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configure GPIO
|
// Configure GPIO
|
||||||
pinmap_pinout(pin, PinMap_DAC);
|
pinmap_pinout(pin, PinMap_DAC);
|
||||||
|
|
|
@ -64,7 +64,7 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void gpio_dir(gpio_t *obj, PinDirection direction) {
|
void gpio_dir(gpio_t *obj, PinDirection direction) {
|
||||||
assert(pin != (PinName)NC);
|
assert(obj->pin != (PinName)NC);
|
||||||
if (direction == PIN_OUTPUT) {
|
if (direction == PIN_OUTPUT) {
|
||||||
pin_function(obj->pin, STM_PIN_DATA(STM_MODE_OUTPUT_PP, GPIO_NOPULL, 0));
|
pin_function(obj->pin, STM_PIN_DATA(STM_MODE_OUTPUT_PP, GPIO_NOPULL, 0));
|
||||||
} else { // PIN_INPUT
|
} else { // PIN_INPUT
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "i2c_api.h"
|
#include "i2c_api.h"
|
||||||
|
|
||||||
#if DEVICE_I2C
|
#if DEVICE_I2C
|
||||||
|
@ -65,10 +66,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
|
||||||
I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
|
I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
|
||||||
|
|
||||||
obj->i2c = (I2CName)pinmap_merge(i2c_sda, i2c_scl);
|
obj->i2c = (I2CName)pinmap_merge(i2c_sda, i2c_scl);
|
||||||
|
assert(obj->i2c != (I2CName)NC);
|
||||||
if (obj->i2c == (I2CName)NC) {
|
|
||||||
error("I2C error: pinout mapping failed.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable I2C clock
|
// Enable I2C clock
|
||||||
if (obj->i2c == I2C_1) {
|
if (obj->i2c == I2C_1) {
|
||||||
|
@ -92,6 +90,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void i2c_frequency(i2c_t *obj, int hz) {
|
void i2c_frequency(i2c_t *obj, int hz) {
|
||||||
|
assert((hz == 100000) || (hz == 400000) || (hz == 1000000));
|
||||||
I2cHandle.Instance = (I2C_TypeDef *)(obj->i2c);
|
I2cHandle.Instance = (I2C_TypeDef *)(obj->i2c);
|
||||||
|
|
||||||
// Common settings: I2C clock = 32 MHz, Analog filter = ON, Digital filter coefficient = 0
|
// Common settings: I2C clock = 32 MHz, Analog filter = ON, Digital filter coefficient = 0
|
||||||
|
@ -106,7 +105,6 @@ void i2c_frequency(i2c_t *obj, int hz) {
|
||||||
I2cHandle.Init.Timing = 0x0030040E; // Fast mode Plus with Rise Time = 60ns and Fall Time = 100ns
|
I2cHandle.Init.Timing = 0x0030040E; // Fast mode Plus with Rise Time = 60ns and Fall Time = 100ns
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
error("Only 100kHz, 400kHz and 1MHz I2C frequencies are supported.");
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,13 +27,13 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "serial_api.h"
|
#include "serial_api.h"
|
||||||
|
|
||||||
#if DEVICE_SERIAL
|
#if DEVICE_SERIAL
|
||||||
|
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
static const PinMap PinMap_UART_TX[] = {
|
static const PinMap PinMap_UART_TX[] = {
|
||||||
|
@ -98,10 +98,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
|
||||||
|
|
||||||
// Get the peripheral name (UART_1, UART_2, ...) from the pin and assign it to the object
|
// Get the peripheral name (UART_1, UART_2, ...) from the pin and assign it to the object
|
||||||
obj->uart = (UARTName)pinmap_merge(uart_tx, uart_rx);
|
obj->uart = (UARTName)pinmap_merge(uart_tx, uart_rx);
|
||||||
|
assert(obj->uart != (UARTName)NC);
|
||||||
if (obj->uart == (UARTName)NC) {
|
|
||||||
error("Serial error: pinout mapping failed.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable UART clock
|
// Enable UART clock
|
||||||
if (obj->uart == UART_1) {
|
if (obj->uart == UART_1) {
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "spi_api.h"
|
#include "spi_api.h"
|
||||||
|
|
||||||
#if DEVICE_SPI
|
#if DEVICE_SPI
|
||||||
|
@ -34,7 +35,6 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
|
|
||||||
static const PinMap PinMap_SPI_MOSI[] = {
|
static const PinMap PinMap_SPI_MOSI[] = {
|
||||||
{PA_7, SPI_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF0_SPI1)},
|
{PA_7, SPI_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF0_SPI1)},
|
||||||
|
@ -105,10 +105,7 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
|
||||||
SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel);
|
SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel);
|
||||||
|
|
||||||
obj->spi = (SPIName)pinmap_merge(spi_data, spi_cntl);
|
obj->spi = (SPIName)pinmap_merge(spi_data, spi_cntl);
|
||||||
|
assert(obj->spi != (SPIName)NC);
|
||||||
if (obj->spi == (SPIName)NC) {
|
|
||||||
error("SPI error: pinout mapping failed.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable SPI clock
|
// Enable SPI clock
|
||||||
if (obj->spi == SPI_1) {
|
if (obj->spi == SPI_1) {
|
||||||
|
|
|
@ -25,13 +25,13 @@
|
||||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "analogin_api.h"
|
#include "analogin_api.h"
|
||||||
|
|
||||||
#if DEVICE_ANALOGIN
|
#if DEVICE_ANALOGIN
|
||||||
|
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
#include "wait_api.h"
|
#include "wait_api.h"
|
||||||
|
|
||||||
static const PinMap PinMap_ADC[] = {
|
static const PinMap PinMap_ADC[] = {
|
||||||
|
@ -66,10 +66,7 @@ void analogin_init(analogin_t *obj, PinName pin) {
|
||||||
|
|
||||||
// Get the peripheral name from the pin and assign it to the object
|
// Get the peripheral name from the pin and assign it to the object
|
||||||
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
|
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
|
||||||
|
assert(obj->adc != (ADCName)NC);
|
||||||
if (obj->adc == (ADCName)NC) {
|
|
||||||
error("ADC pin mapping failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configure GPIO
|
// Configure GPIO
|
||||||
pinmap_pinout(pin, PinMap_ADC);
|
pinmap_pinout(pin, PinMap_ADC);
|
||||||
|
|
|
@ -25,13 +25,13 @@
|
||||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "analogout_api.h"
|
#include "analogout_api.h"
|
||||||
|
|
||||||
#if DEVICE_ANALOGOUT
|
#if DEVICE_ANALOGOUT
|
||||||
|
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
|
|
||||||
#define RANGE_12BIT (0xFFF)
|
#define RANGE_12BIT (0xFFF)
|
||||||
|
|
||||||
|
@ -46,10 +46,7 @@ void analogout_init(dac_t *obj, PinName pin) {
|
||||||
|
|
||||||
// Get the peripheral name (DAC_1, ...) from the pin and assign it to the object
|
// Get the peripheral name (DAC_1, ...) from the pin and assign it to the object
|
||||||
obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC);
|
obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC);
|
||||||
|
assert(obj->dac != (DACName)NC);
|
||||||
if (obj->dac == (DACName)NC) {
|
|
||||||
error("DAC pin mapping failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configure GPIO
|
// Configure GPIO
|
||||||
pinmap_pinout(pin, PinMap_DAC);
|
pinmap_pinout(pin, PinMap_DAC);
|
||||||
|
|
|
@ -27,13 +27,14 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "i2c_api.h"
|
#include "i2c_api.h"
|
||||||
|
|
||||||
#if DEVICE_I2C
|
#if DEVICE_I2C
|
||||||
|
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
|
|
||||||
/* Timeout values for flags and events waiting loops. These timeouts are
|
/* Timeout values for flags and events waiting loops. These timeouts are
|
||||||
not based on accurate values, they just guarantee that the application will
|
not based on accurate values, they just guarantee that the application will
|
||||||
|
@ -61,10 +62,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
|
||||||
I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
|
I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
|
||||||
|
|
||||||
obj->i2c = (I2CName)pinmap_merge(i2c_sda, i2c_scl);
|
obj->i2c = (I2CName)pinmap_merge(i2c_sda, i2c_scl);
|
||||||
|
assert(obj->i2c != (I2CName)NC);
|
||||||
if (obj->i2c == (I2CName)NC) {
|
|
||||||
error("I2C pin mapping failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable I2C clock
|
// Enable I2C clock
|
||||||
if (obj->i2c == I2C_1) {
|
if (obj->i2c == I2C_1) {
|
||||||
|
|
|
@ -27,13 +27,13 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "pwmout_api.h"
|
#include "pwmout_api.h"
|
||||||
|
|
||||||
#if DEVICE_PWMOUT
|
#if DEVICE_PWMOUT
|
||||||
|
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
|
|
||||||
// TIM5 cannot be used because already used by the us_ticker
|
// TIM5 cannot be used because already used by the us_ticker
|
||||||
static const PinMap PinMap_PWM[] = {
|
static const PinMap PinMap_PWM[] = {
|
||||||
|
@ -77,10 +77,7 @@ static const PinMap PinMap_PWM[] = {
|
||||||
void pwmout_init(pwmout_t* obj, PinName pin) {
|
void pwmout_init(pwmout_t* obj, PinName pin) {
|
||||||
// Get the peripheral name from the pin and assign it to the object
|
// Get the peripheral name from the pin and assign it to the object
|
||||||
obj->pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
|
obj->pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
|
||||||
|
assert(obj->pwm != (PWMName)NC);
|
||||||
if (obj->pwm == (PWMName)NC) {
|
|
||||||
error("PWM pinout mapping failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable TIM clock
|
// Enable TIM clock
|
||||||
if (obj->pwm == PWM_2) RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
|
if (obj->pwm == PWM_2) RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
|
||||||
|
|
|
@ -27,13 +27,13 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "serial_api.h"
|
#include "serial_api.h"
|
||||||
|
|
||||||
#if DEVICE_SERIAL
|
#if DEVICE_SERIAL
|
||||||
|
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
static const PinMap PinMap_UART_TX[] = {
|
static const PinMap PinMap_UART_TX[] = {
|
||||||
|
@ -91,10 +91,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
|
||||||
|
|
||||||
// Get the peripheral name (UART_1, UART_2, ...) from the pin and assign it to the object
|
// Get the peripheral name (UART_1, UART_2, ...) from the pin and assign it to the object
|
||||||
obj->uart = (UARTName)pinmap_merge(uart_tx, uart_rx);
|
obj->uart = (UARTName)pinmap_merge(uart_tx, uart_rx);
|
||||||
|
assert(obj->uart != (UARTName)NC);
|
||||||
if (obj->uart == (UARTName)NC) {
|
|
||||||
error("Serial pinout mapping failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable USART clock
|
// Enable USART clock
|
||||||
if (obj->uart == UART_1) {
|
if (obj->uart == UART_1) {
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "spi_api.h"
|
#include "spi_api.h"
|
||||||
|
|
||||||
#if DEVICE_SPI
|
#if DEVICE_SPI
|
||||||
|
@ -34,7 +35,6 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
|
|
||||||
static const PinMap PinMap_SPI_MOSI[] = {
|
static const PinMap PinMap_SPI_MOSI[] = {
|
||||||
{PA_7, SPI_1, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_SPI1)},
|
{PA_7, SPI_1, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_SPI1)},
|
||||||
|
@ -105,10 +105,7 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
|
||||||
SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel);
|
SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel);
|
||||||
|
|
||||||
obj->spi = (SPIName)pinmap_merge(spi_data, spi_cntl);
|
obj->spi = (SPIName)pinmap_merge(spi_data, spi_cntl);
|
||||||
|
assert(obj->spi != (SPIName)NC);
|
||||||
if (obj->spi == (SPIName)NC) {
|
|
||||||
error("SPI pinout mapping failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable SPI clock
|
// Enable SPI clock
|
||||||
if (obj->spi == SPI_1) {
|
if (obj->spi == SPI_1) {
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "analogin_api.h"
|
#include "analogin_api.h"
|
||||||
#include "wait_api.h"
|
#include "wait_api.h"
|
||||||
|
|
||||||
|
@ -32,7 +33,6 @@
|
||||||
|
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
|
|
||||||
static const PinMap PinMap_ADC[] = {
|
static const PinMap PinMap_ADC[] = {
|
||||||
{PA_0, ADC_1, STM_PIN_DATA(GPIO_Mode_AN, GPIO_OType_PP, GPIO_PuPd_NOPULL, 0xFF)}, // ADC_IN1
|
{PA_0, ADC_1, STM_PIN_DATA(GPIO_Mode_AN, GPIO_OType_PP, GPIO_PuPd_NOPULL, 0xFF)}, // ADC_IN1
|
||||||
|
@ -63,10 +63,7 @@ void analogin_init(analogin_t *obj, PinName pin) {
|
||||||
|
|
||||||
// Get the peripheral name from the pin and assign it to the object
|
// Get the peripheral name from the pin and assign it to the object
|
||||||
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
|
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
|
||||||
|
assert(obj->adc == (ADCName)NC);
|
||||||
if (obj->adc == (ADCName)NC) {
|
|
||||||
error("ADC pin mapping failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configure GPIO
|
// Configure GPIO
|
||||||
pinmap_pinout(pin, PinMap_ADC);
|
pinmap_pinout(pin, PinMap_ADC);
|
||||||
|
|
|
@ -25,13 +25,13 @@
|
||||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "analogout_api.h"
|
#include "analogout_api.h"
|
||||||
|
|
||||||
#if DEVICE_ANALOGOUT
|
#if DEVICE_ANALOGOUT
|
||||||
|
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
|
|
||||||
#define RANGE_12BIT (0xFFF)
|
#define RANGE_12BIT (0xFFF)
|
||||||
|
|
||||||
|
@ -46,10 +46,7 @@ void analogout_init(dac_t *obj, PinName pin) {
|
||||||
|
|
||||||
// Get the peripheral name (DAC_1, ...) from the pin and assign it to the object
|
// Get the peripheral name (DAC_1, ...) from the pin and assign it to the object
|
||||||
obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC);
|
obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC);
|
||||||
|
assert(obj->dac == (DACName)NC);
|
||||||
if (obj->dac == (DACName)NC) {
|
|
||||||
error("DAC pin mapping failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
dac = (DAC_TypeDef *)(obj->dac);
|
dac = (DAC_TypeDef *)(obj->dac);
|
||||||
|
|
||||||
|
|
|
@ -27,13 +27,13 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "i2c_api.h"
|
#include "i2c_api.h"
|
||||||
|
|
||||||
#if DEVICE_I2C
|
#if DEVICE_I2C
|
||||||
|
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
|
|
||||||
/* Timeout values for flags and events waiting loops. These timeouts are
|
/* Timeout values for flags and events waiting loops. These timeouts are
|
||||||
not based on accurate values, they just guarantee that the application will
|
not based on accurate values, they just guarantee that the application will
|
||||||
|
@ -68,10 +68,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
|
||||||
I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
|
I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
|
||||||
|
|
||||||
obj->i2c = (I2CName)pinmap_merge(i2c_sda, i2c_scl);
|
obj->i2c = (I2CName)pinmap_merge(i2c_sda, i2c_scl);
|
||||||
|
assert(obj->i2c != (I2CName)NC);
|
||||||
if (obj->i2c == (I2CName)NC) {
|
|
||||||
error("I2C pin mapping failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable I2C clock
|
// Enable I2C clock
|
||||||
if (obj->i2c == I2C_1) {
|
if (obj->i2c == I2C_1) {
|
||||||
|
@ -98,6 +95,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void i2c_frequency(i2c_t *obj, int hz) {
|
void i2c_frequency(i2c_t *obj, int hz) {
|
||||||
|
assert((hz == 100000) || (hz == 200000) || (hz == 400000) || (hz == 1000000));
|
||||||
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
|
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
|
||||||
I2C_InitTypeDef I2C_InitStructure;
|
I2C_InitTypeDef I2C_InitStructure;
|
||||||
uint32_t tim;
|
uint32_t tim;
|
||||||
|
@ -140,7 +138,6 @@ void i2c_frequency(i2c_t *obj, int hz) {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
error("Only 100kHz, 200kHz, 400kHz and 1MHz I2C frequencies are supported.");
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,11 +27,11 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "pwmout_api.h"
|
#include "pwmout_api.h"
|
||||||
|
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
|
|
||||||
// TIM2 cannot be used because already used by the us_ticker
|
// TIM2 cannot be used because already used by the us_ticker
|
||||||
static const PinMap PinMap_PWM[] = {
|
static const PinMap PinMap_PWM[] = {
|
||||||
|
@ -88,10 +88,7 @@ static const PinMap PinMap_PWM[] = {
|
||||||
void pwmout_init(pwmout_t* obj, PinName pin) {
|
void pwmout_init(pwmout_t* obj, PinName pin) {
|
||||||
// Get the peripheral name from the pin and assign it to the object
|
// Get the peripheral name from the pin and assign it to the object
|
||||||
obj->pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
|
obj->pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
|
||||||
|
assert(obj->pwm == (PWMName)NC);
|
||||||
if (obj->pwm == (PWMName)NC) {
|
|
||||||
error("PWM pinout mapping failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable TIM clock
|
// Enable TIM clock
|
||||||
if (obj->pwm == PWM_1) RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
|
if (obj->pwm == PWM_1) RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
|
||||||
|
|
|
@ -27,10 +27,10 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "serial_api.h"
|
#include "serial_api.h"
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
static const PinMap PinMap_UART_TX[] = {
|
static const PinMap PinMap_UART_TX[] = {
|
||||||
|
@ -92,10 +92,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
|
||||||
|
|
||||||
// Get the peripheral name from the pin and assign it to the object
|
// Get the peripheral name from the pin and assign it to the object
|
||||||
obj->uart = (UARTName)pinmap_merge(uart_tx, uart_rx);
|
obj->uart = (UARTName)pinmap_merge(uart_tx, uart_rx);
|
||||||
|
assert(obj->uart != (UARTName)NC);
|
||||||
if (obj->uart == (UARTName)NC) {
|
|
||||||
error("Serial pinout mapping failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable USART clock
|
// Enable USART clock
|
||||||
if (obj->uart == UART_1) {
|
if (obj->uart == UART_1) {
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "spi_api.h"
|
#include "spi_api.h"
|
||||||
|
|
||||||
#if DEVICE_SPI
|
#if DEVICE_SPI
|
||||||
|
@ -34,7 +35,6 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
|
|
||||||
static const PinMap PinMap_SPI_MOSI[] = {
|
static const PinMap PinMap_SPI_MOSI[] = {
|
||||||
{PA_11, SPI_2, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_DOWN, GPIO_AF_5)},
|
{PA_11, SPI_2, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_DOWN, GPIO_AF_5)},
|
||||||
|
@ -102,9 +102,7 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
|
||||||
|
|
||||||
obj->spi = (SPIName)pinmap_merge(spi_data, spi_cntl);
|
obj->spi = (SPIName)pinmap_merge(spi_data, spi_cntl);
|
||||||
|
|
||||||
if (obj->spi == (SPIName)NC) {
|
assert(obj->spi != (SPIName)NC);
|
||||||
error("SPI pinout mapping failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable SPI clock
|
// Enable SPI clock
|
||||||
if (obj->spi == SPI_2) {
|
if (obj->spi == SPI_2) {
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "analogin_api.h"
|
#include "analogin_api.h"
|
||||||
|
|
||||||
#if DEVICE_ANALOGIN
|
#if DEVICE_ANALOGIN
|
||||||
|
@ -48,9 +49,7 @@ static const PinMap PinMap_ADC[] = {
|
||||||
|
|
||||||
void analogin_init(analogin_t *obj, PinName pin) {
|
void analogin_init(analogin_t *obj, PinName pin) {
|
||||||
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
|
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
|
||||||
if (obj->adc == (uint32_t)NC) {
|
assert(obj->adc != (uint32_t)NC);
|
||||||
error("ADC pin mapping failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
// ensure power is turned on
|
// ensure power is turned on
|
||||||
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN | RCC_AHB1ENR_GPIOBEN |
|
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN | RCC_AHB1ENR_GPIOBEN |
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "i2c_api.h"
|
#include "i2c_api.h"
|
||||||
|
|
||||||
#if DEVICE_I2C
|
#if DEVICE_I2C
|
||||||
|
@ -124,10 +125,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
|
||||||
I2CName i2c_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA);
|
I2CName i2c_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA);
|
||||||
I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
|
I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
|
||||||
obj->i2c = (I2C_TypeDef *)pinmap_merge(i2c_sda, i2c_scl);
|
obj->i2c = (I2C_TypeDef *)pinmap_merge(i2c_sda, i2c_scl);
|
||||||
|
assert((int)obj->i2c != NC);
|
||||||
if ((int)obj->i2c == NC) {
|
|
||||||
error("I2C pin mapping failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
// enable power
|
// enable power
|
||||||
i2c_power_enable(obj);
|
i2c_power_enable(obj);
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
#include <assert.h>
|
||||||
#include "spi_api.h"
|
#include "spi_api.h"
|
||||||
|
|
||||||
#if DEVICE_SPI
|
#if DEVICE_SPI
|
||||||
|
@ -20,7 +21,6 @@
|
||||||
|
|
||||||
#include "cmsis.h"
|
#include "cmsis.h"
|
||||||
#include "pinmap.h"
|
#include "pinmap.h"
|
||||||
#include "error.h"
|
|
||||||
|
|
||||||
static const PinMap PinMap_SPI_SCLK[] = {
|
static const PinMap PinMap_SPI_SCLK[] = {
|
||||||
{PA_5, SPI_1, STM_PIN_DATA(2, 5)},
|
{PA_5, SPI_1, STM_PIN_DATA(2, 5)},
|
||||||
|
@ -75,9 +75,7 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
|
||||||
SPIName spi_data = (SPIName)pinmap_merge(spi_mosi, spi_miso);
|
SPIName spi_data = (SPIName)pinmap_merge(spi_mosi, spi_miso);
|
||||||
SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel);
|
SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel);
|
||||||
obj->spi = (SPI_TypeDef*)pinmap_merge(spi_data, spi_cntl);
|
obj->spi = (SPI_TypeDef*)pinmap_merge(spi_data, spi_cntl);
|
||||||
if ((int)obj->spi == NC) {
|
assert((int)obj->spi != NC)
|
||||||
error("SPI pinout mapping failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
// enable power and clocking
|
// enable power and clocking
|
||||||
switch ((int)obj->spi) {
|
switch ((int)obj->spi) {
|
||||||
|
@ -123,13 +121,9 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
|
||||||
void spi_free(spi_t *obj) {}
|
void spi_free(spi_t *obj) {}
|
||||||
|
|
||||||
void spi_format(spi_t *obj, int bits, int mode, int slave) {
|
void spi_format(spi_t *obj, int bits, int mode, int slave) {
|
||||||
|
assert((bits == 8 || bits == 16) || (mode >= 0 && mode <= 3));
|
||||||
ssp_disable(obj);
|
ssp_disable(obj);
|
||||||
|
|
||||||
if (!(bits == 8 || bits == 16) || !(mode >= 0 && mode <= 3)) {
|
|
||||||
error("SPI format error");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int polarity = (mode & 0x2) ? 1 : 0;
|
int polarity = (mode & 0x2) ? 1 : 0;
|
||||||
int phase = (mode & 0x1) ? 1 : 0;
|
int phase = (mode & 0x1) ? 1 : 0;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue