Skip to content

Commit

Permalink
Merge pull request #235 from boramonideep/develop
Browse files Browse the repository at this point in the history
Refactored built-in libraries
  • Loading branch information
boramonideep committed Apr 5, 2023
2 parents bf9a1a1 + 73cfd6a commit b74cf8f
Show file tree
Hide file tree
Showing 19 changed files with 907 additions and 1,019 deletions.
68 changes: 68 additions & 0 deletions cores/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ extern "C" {
#include <xmc_uart.h>
#include <xmc_dac.h>
#include <xmc_eru.h>
#include <xmc_spi.h>
#include <xmc_i2c.h>
#include <xmc_i2s.h>

//****************************************************************************
// @Defines
Expand All @@ -55,6 +58,13 @@ extern "C" {
#define clockCyclesToMicroseconds(a) ( ((a) * 1000L) / (F_CPU / 1000L) )
#define microsecondsToClockCycles(a) ( (a) * (F_CPU / 1000000L) )

// default XMC_SPI instance is XMC_SPI_0 for all variants
#define XMC_SPI_default XMC_SPI_0
// default XMC_I2C instance is XMC_I2C_0 for all variants
#define XMC_I2C_default XMC_I2C_0
// used by XMC_I2S
#define BUFFER_SIZE 512

//****************************************************************************
// @Typedefs
//****************************************************************************
Expand Down Expand Up @@ -187,6 +197,53 @@ extern "C" {
uint32_t irq_service_request ;
} XMC_UART_t;

/*
* XMC SPI type
*/
typedef struct
{
XMC_USIC_CH_t* channel ;
XMC_SPI_CH_CONFIG_t channel_config ;
XMC_PORT_PIN_t mosi ;
XMC_GPIO_CONFIG_t mosi_config ;
XMC_PORT_PIN_t miso ;
XMC_GPIO_CONFIG_t miso_config ;
XMC_USIC_INPUT_t input_source ;
XMC_PORT_PIN_t sclkout ;
XMC_GPIO_CONFIG_t sclkout_config ;
} XMC_SPI_t;

/*
* XMC I2C type
*/
typedef struct
{
XMC_USIC_CH_t* channel;
XMC_I2C_CH_CONFIG_t channel_config;
XMC_PORT_PIN_t sda;
XMC_GPIO_CONFIG_t sda_config;
XMC_PORT_PIN_t scl;
XMC_GPIO_CONFIG_t scl_config;
XMC_USIC_INPUT_t input_source_dx0;
XMC_USIC_INPUT_t input_source_dx1;
IRQn_Type slave_receive_irq_num;
uint32_t slave_receive_irq_service_request;
IRQn_Type protocol_irq_num;
uint32_t protocol_irq_service_request;
} XMC_I2C_t;

/*
* XMC I2S type
*/
typedef struct
{
XMC_GPIO_CONFIG_t input_config;
XMC_GPIO_CONFIG_t sclk_config;
XMC_GPIO_CONFIG_t wa_config;
IRQn_Type protocol_irq_num;
uint32_t protocol_irq_service_request;
} XMC_I2S_t;

//****************************************************************************
// @Imported Global Variables
//****************************************************************************
Expand All @@ -205,6 +262,17 @@ extern "C" {
#endif
extern XMC_UART_t XMC_UART_debug;
extern XMC_UART_t XMC_UART_on_board;

extern XMC_SPI_t XMC_SPI_0;
// Some boards for eg. XMC4700 Relax Kit has more than one SPI instance
extern XMC_SPI_t XMC_SPI_1;
extern XMC_SPI_t XMC_SPI_2;

extern XMC_I2C_t XMC_I2C_0;
// Some boards for eg. XMC4700 Relax Kit has more than one I2C instance
extern XMC_I2C_t XMC_I2C_1;

extern XMC_I2S_t i2s_config;

//****************************************************************************
// @Prototypes Of Global Functions
Expand Down
2 changes: 1 addition & 1 deletion libraries/I2S/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ The library has been tested with the XMC4700 Relax Kit, XMC1100 XMC 2Go, and XMC

`Ensure that level shifting is in place as the microphone board has 3.3 V logic level, XMC1100 Boot Kit has 5 V by default.`

This configuration is defined in `utility\xmc_i2s_conf.h`.
This configuration is defined in the respective board configuration files `pins_arduino.h`.

If we take the pin out of XMC for Arduino, the respective pins for SPI are redefined.
Therefore, SPI cannot be used anymore in combination with I2S - please keep this in mind. On the other hand, using `SPI.begin()` and `I2S.begin()` will reactivate the original setting and switching between both interfaces is possible on the fly.
Expand Down
7 changes: 0 additions & 7 deletions libraries/I2S/src/I2S.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@
#ifndef I2S_h
#define I2S_h

#if defined(XMC4700_Relax_Kit) || defined(XMC1100_XMC2GO) || defined(XMC1100_Boot_Kit)
#include "utility/xmc_i2s_conf.h"

typedef enum {
I2S_PHILIPS_MODE,
I2S_RIGHT_JUSTIFIED_MODE,
Expand Down Expand Up @@ -260,8 +257,4 @@ class I2SClass

extern I2SClass I2S;

#else
#error "Only XMC4700 Relax Kit, XMC1100 XMC2Go or XMC1100 Boot Kit is supported for I2S"
#endif

#endif /* I2S_h */
18 changes: 0 additions & 18 deletions libraries/I2S/src/utility/xmc_i2s_conf.c

This file was deleted.

95 changes: 0 additions & 95 deletions libraries/I2S/src/utility/xmc_i2s_conf.h

This file was deleted.

6 changes: 2 additions & 4 deletions libraries/SPI/src/SPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,8 @@
#define SPI_CLOCK_DIV128 128


#if !defined(USE_SW_SPI)
#include "utility/xmc_spi_conf.h"
#else
#include "utility/SW_SPI.h"
#if defined(USE_SW_SPI)
#include "SW_SPI.h"
#endif

//#define pin_cs 10
Expand Down
File renamed without changes.
Loading

0 comments on commit b74cf8f

Please sign in to comment.