-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cpu/rpx0xx: Add PIO I2C implementation
- Loading branch information
Showing
15 changed files
with
1,025 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
CPU := rpx0xx | ||
|
||
# Put defined MCU peripherals here (in alphabetical order) | ||
FEATURES_PROVIDED += periph_i2c | ||
FEATURES_PROVIDED += periph_timer | ||
FEATURES_PROVIDED += periph_uart |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* Copyright (C) 2021 Otto-von-Guericke Universität Magdeburg | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser | ||
* General Public License v2.1. See the file LICENSE in the top level | ||
* directory for more details. | ||
*/ | ||
|
||
/** | ||
* @ingroup cpu_rpx0xx | ||
* @ingroup drivers_periph_i2c | ||
* @{ | ||
* | ||
* @file | ||
* @brief Low-level I2C driver implementation | ||
* | ||
* @note This driver is so far only a dummy implementation | ||
* to test the PIO I2C interface. | ||
* | ||
* @author Fabian Hüßler <fabian.huessler@ovgu.de> | ||
* @} | ||
*/ | ||
|
||
#include <errno.h> | ||
|
||
#include "periph_conf.h" | ||
#include "periph/i2c.h" | ||
#include "periph/pio/i2c.h" | ||
|
||
int i2c_acquire(i2c_t dev) | ||
{ | ||
if (IS_USED(MODULE_PIO_I2C) && (int)dev >= I2C_NUMOF) { | ||
pio_i2c_obj_t *i2c = pio_i2c_get(dev - I2C_NUMOF); | ||
return i2c ? pio_i2c_acquire(&i2c->pro) : -EFAULT; | ||
} | ||
return -ENOTSUP; | ||
} | ||
|
||
void i2c_release(i2c_t dev) | ||
{ | ||
if (IS_USED(MODULE_PIO_I2C) && (int)dev >= I2C_NUMOF) { | ||
pio_i2c_obj_t *i2c = pio_i2c_get(dev - I2C_NUMOF); | ||
if (i2c) { | ||
pio_i2c_release(&i2c->pro); | ||
} | ||
} | ||
} | ||
|
||
int i2c_read_bytes(i2c_t dev, uint16_t addr, void *data, | ||
size_t len, uint8_t flags) | ||
{ | ||
if (IS_USED(MODULE_PIO_I2C) && (int)dev >= I2C_NUMOF) { | ||
pio_i2c_obj_t *i2c = pio_i2c_get(dev - I2C_NUMOF); | ||
return i2c ? pio_i2c_read_bytes(i2c->pio, i2c->sm, addr, data, len, flags) : -EFAULT; | ||
} | ||
return -ENOTSUP; | ||
} | ||
|
||
int i2c_read_regs(i2c_t dev, uint16_t addr, uint16_t reg, | ||
void *data, size_t len, uint8_t flags) | ||
{ | ||
if (IS_USED(MODULE_PIO_I2C) && (int)dev >= I2C_NUMOF) { | ||
pio_i2c_obj_t *i2c = pio_i2c_get(dev - I2C_NUMOF); | ||
return i2c ? pio_i2c_read_regs(i2c->pio, i2c->sm, addr, reg, data, len, flags) : -EFAULT; | ||
} | ||
return -ENOTSUP; | ||
} | ||
|
||
int i2c_read_reg(i2c_t dev, uint16_t addr, uint16_t reg, | ||
void *data, uint8_t flags) | ||
{ | ||
return i2c_read_regs(dev, addr, reg, data, 1, flags); | ||
} | ||
|
||
int i2c_write_bytes(i2c_t dev, uint16_t addr, const void *data, | ||
size_t len, uint8_t flags) | ||
{ | ||
if (IS_USED(MODULE_PIO_I2C) && (int)dev >= I2C_NUMOF) { | ||
pio_i2c_obj_t *i2c = pio_i2c_get(dev - I2C_NUMOF); | ||
return i2c ? pio_i2c_write_bytes(i2c->pio, i2c->sm, addr, data, len, flags) : -EFAULT; | ||
} | ||
return -ENOTSUP; | ||
} | ||
|
||
int i2c_write_regs(i2c_t dev, uint16_t addr, uint16_t reg, | ||
const void *data, size_t len, uint8_t flags) | ||
{ | ||
if (IS_USED(MODULE_PIO_I2C) && (int)dev >= I2C_NUMOF) { | ||
pio_i2c_obj_t *i2c = pio_i2c_get(dev - I2C_NUMOF); | ||
return i2c ? pio_i2c_write_regs(i2c->pio, i2c->sm, addr, reg, data, len, flags) : -EFAULT; | ||
} | ||
return -ENOTSUP; | ||
} | ||
|
||
int i2c_write_reg(i2c_t dev, uint16_t addr, uint16_t reg, | ||
uint8_t data, uint8_t flags) | ||
{ | ||
return i2c_write_regs(dev, addr, reg, &data, 1, flags); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
MODULE = pio_i2c | ||
|
||
include $(RIOTBASE)/Makefile.base | ||
|
||
i2c.c: i2c.hex.pio.h i2c_set_scl_sda.hex.pio.h | ||
|
||
i2c.hex.pio.h: i2c.pio | ||
$(Q) $(RIOTCPU)/$(CPU)/dist/pioasm.bash $< $@ | ||
|
||
i2c_set_scl_sda.hex.pio.h: i2c_set_scl_sda.pio | ||
$(Q) $(RIOTCPU)/$(CPU)/dist/pioasm.bash $< $@ |
Oops, something went wrong.