Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for Siemens Simatic IOT2050 Basic/Advanced #618

Merged
merged 2 commits into from
Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/adafruit_blinka/board/siemens/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# SPDX-FileCopyrightText: 2022 Martin Schnur for Siemens AG
#
# SPDX-License-Identifier: MIT
"""Boards definition from Siemens AG"""
60 changes: 60 additions & 0 deletions src/adafruit_blinka/board/siemens/siemens_iot2050.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# SPDX-FileCopyrightText: 2022 Martin Schnur for Siemens AG
#
# SPDX-License-Identifier: MIT
"""Pin definitions for the Siemens Simatic IOT2050 Basic/Advanced."""
# Output Pins are the same as Arduino Uno R3,Overall 31 + 1 Pins !

from adafruit_blinka.microcontroller.am65xx import pin

# Digital Pins
D0 = pin.D0
D1 = pin.D1
D2 = pin.D2
D3 = pin.D3
D4 = pin.D4
D5 = pin.D5
D6 = pin.D6
D7 = pin.D7
D8 = pin.D8
D9 = pin.D9
D10 = pin.D10
D11 = pin.D11
D12 = pin.D12
D13 = pin.D13
D14 = pin.D14
D15 = pin.D15
D16 = pin.D16
D17 = pin.D17
D18 = pin.D18
D19 = pin.D19

# Analog Pins
A0 = pin.A0
A1 = pin.A1
A2 = pin.A2
A3 = pin.A3
A4 = pin.A4
A5 = pin.A5

# I2C allocation
SCL = pin.I2C_SCL
SDA = pin.I2C_SDA

# SPI allocation
SCLK = pin.SPIO_SCLK
MOSI = pin.SPIO_MOSI
MISO = pin.SPIO_MISO
SS = pin.SPIO_SS

# UART allocation
UART_TX = pin.UART_TX
UART_RX = pin.UART_RX


# PWM allocation
PWM_4 = pin.PWM_4
PWM_5 = pin.PWM_5
PWM_6 = pin.PWM_6
PWM_7 = pin.PWM_7
PWM_8 = pin.PWM_8
PWM_9 = pin.PWM_9
Empty file.
57 changes: 57 additions & 0 deletions src/adafruit_blinka/microcontroller/am65xx/analogio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
#
# SPDX-License-Identifier: MIT
"""
`analogio` - Analog input and output control
=================================================
See `CircuitPython:analogio` in CircuitPython for more details.
* Author(s): Martin Schnur
"""

from adafruit_blinka.microcontroller.am65xx.pin import Pin
from adafruit_blinka import ContextManaged


class AnalogIn(ContextManaged):
"""Analog Input Class"""

def __init__(self, pin):
self._pin = Pin(pin.id)
self._pin.init(mode=Pin.ADC)

@property
def value(self):
"""Read the ADC and return the value"""
return self._pin.value()

# pylint: disable=no-self-use
@value.setter
def value(self, value):
# emulate what CircuitPython does
raise AttributeError("'AnalogIn' object has no attribute 'value'")

# pylint: enable=no-self-use

def deinit(self):
del self._pin


class AnalogOut(ContextManaged):
"""Analog Output Class"""

def __init__(self, pin):
self._pin = Pin(pin.id)
self._pin.init(mode=Pin.DAC)

@property
def value(self):
"""Return an error. This is output only."""
# emulate what CircuitPython does
raise AttributeError("AM65xx doesn't have an DAC! No Analog Output possible!")

@value.setter
def value(self, value):
self._pin.value(value)

def deinit(self):
del self._pin
94 changes: 94 additions & 0 deletions src/adafruit_blinka/microcontroller/am65xx/i2c.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
#
# SPDX-License-Identifier: MIT
"""Generic Linux I2C class using PureIO's smbus class"""
from Adafruit_PureIO import smbus


class I2C:
"""I2C class"""

MASTER = 0
SLAVE = 1
_baudrate = None
_mode = None
_i2c_bus = None

# pylint: disable=unused-argument
def __init__(self, bus_num, mode=MASTER, baudrate=None):
if mode != self.MASTER:
raise NotImplementedError("Only I2C Master supported!")
_mode = self.MASTER

# if baudrate != None:
# print("I2C frequency is not settable in python, ignoring!")

try:
self._i2c_bus = smbus.SMBus(bus_num)
except FileNotFoundError:
raise RuntimeError(
"I2C Bus #%d not found, check if enabled in config!" % bus_num
) from RuntimeError

# pylint: enable=unused-argument

def scan(self):
"""Try to read a byte from each address, if you get an OSError
it means the device isnt there"""
found = []
for addr in range(0, 0x80):
try:
self._i2c_bus.read_byte(addr)
except OSError:
continue
found.append(addr)
return found

# pylint: disable=unused-argument
def writeto(self, address, buffer, *, start=0, end=None, stop=True):
"""Write data from the buffer to an address"""
if end is None:
end = len(buffer)
self._i2c_bus.write_bytes(address, buffer[start:end])

def readfrom_into(self, address, buffer, *, start=0, end=None, stop=True):
"""Read data from an address and into the buffer"""
if end is None:
end = len(buffer)

readin = self._i2c_bus.read_bytes(address, end - start)
for i in range(end - start):
buffer[i + start] = readin[i]

# pylint: enable=unused-argument

def writeto_then_readfrom(
self,
address,
buffer_out,
buffer_in,
*,
out_start=0,
out_end=None,
in_start=0,
in_end=None,
stop=False
):
"""Write data from buffer_out to an address and then
read data from an address and into buffer_in
"""
if out_end is None:
out_end = len(buffer_out)
if in_end is None:
in_end = len(buffer_in)
if stop:
# To generate a stop in linux, do in two transactions
self.writeto(address, buffer_out, start=out_start, end=out_end, stop=True)
self.readfrom_into(address, buffer_in, start=in_start, end=in_end)
else:
# To generate without a stop, do in one block transaction
readin = self._i2c_bus.read_i2c_block_data(
address, buffer_out[out_start:out_end], in_end - in_start
)
for i in range(in_end - in_start):
buffer_in[i + in_start] = readin[i]
Loading