Skip to content

Commit

Permalink
adopted new matrixio hal, it now supports also kernel modules
Browse files Browse the repository at this point in the history
  • Loading branch information
cmetz committed Apr 16, 2018
1 parent e1d5378 commit 00098de
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 36 deletions.
15 changes: 5 additions & 10 deletions matrixio_hal/bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ def sigterm_handler(signal, frame):

signal.signal(signal.SIGTERM, sigterm_handler)

bus = matrixio_cpp_hal.PyWishboneBus()
bus.SpiInit()
bus = matrixio_cpp_hal.PyMatrixIOBus()
bus.Init()

# set some infos about the MCU and FPGA
mcu_data = matrixio_cpp_hal.PyMCUData()
Expand All @@ -24,10 +24,8 @@ def sigterm_handler(signal, frame):
del mcu_data
del mcu

fpga_data = matrixio_cpp_hal.PyReadData(struct.calcsize('LL'))
bus.SpiRead(0x0000 >> 1, fpga_data)
FPGA_IDENTIFY, FPGA_FIRMWARE_VERSION = ['{:x}'.format(d) for d in struct.unpack('LL', bytearray(fpga_data.get()))]
del fpga_data
FPGA_IDENTIFY = '{:x}'.format(bus.MatrixName())
FPGA_FIRMWARE_VERSION = '{:x}'.format(bus.MatrixVersion())

MATRIX_DEVICE = 'unknown'
if FPGA_IDENTIFY == '5c344e8':
Expand All @@ -36,8 +34,5 @@ def sigterm_handler(signal, frame):
MATRIX_DEVICE = 'voice'

# set FPGA_FREQUENCY

FPGA_FREQUENCY = 0
if bus.GetFPGAFrequency():
FPGA_FREQUENCY = bus.FPGAClock()
FPGA_FREQUENCY = bus.FPGAClock()

2 changes: 1 addition & 1 deletion matrixio_hal/everloop.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import atexit
import time

EVERLOOP_SIZE = 35 if bus.MATRIX_DEVICE == 'creator' else 18
EVERLOOP_SIZE = bus.bus.MatrixLeds()

COLORS = { # R G B W
"black": [ 0, 0, 0, 0],
Expand Down
53 changes: 29 additions & 24 deletions matrixio_hal/matrixio_cpp_hal.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@ from libcpp.vector cimport vector
from cython.operator cimport dereference as deref
from cython.operator cimport preincrement as incr

cdef extern from "matrix_hal/wishbone_bus.h" namespace "matrix_hal":
cdef cppclass WishboneBus:
WishboneBus() except +
bool SpiInit()
bool SpiRead(uint16_t add, unsigned char* data, int length)
void SpiClose()
bool GetFPGAFrequency()
cdef extern from "matrix_hal/matrixio_bus.h" namespace "matrix_hal":
cdef cppclass MatrixIOBus:
MatrixIOBus() except +
bool Init()
bool Read(uint16_t add, unsigned char* data, int length)
uint32_t FPGAClock()
uint32_t MatrixName()
uint32_t MatrixVersion()
int MatrixLeds()
bool IsDirectBus()

cdef extern from "matrix_hal/matrix_driver.h" namespace "matrix_hal":
cdef cppclass MatrixDriver:
MatrixDriver() except +
void Setup(WishboneBus* wishbone)
void Setup(MatrixIOBus* wishbone)

cdef extern from "matrix_hal/fw_data.h" namespace "matrix_hal":
cdef cppclass MCUData:
Expand Down Expand Up @@ -105,7 +107,7 @@ cdef extern from "matrix_hal/gpio_control.h" namespace "matrix_hal":

cdef cppclass GPIOControl:
GPIOControl() except +
void Setup(WishboneBus* bus)
void Setup(MatrixIOBus* bus)
bool SetMode(uint16_t pin, uint16_t mode)
bool SetFunction(uint16_t pin, uint16_t function)
bool SetGPIOValue(uint16_t pin, uint16_t value)
Expand All @@ -131,28 +133,31 @@ cdef class PyReadData:
def get(self):
return [self.data[i] for i in range(0, self.size)]

cdef class PyWishboneBus:
cdef WishboneBus* thisptr
cdef class PyMatrixIOBus:
cdef MatrixIOBus* thisptr
def __cinit__(self):
self.thisptr = new WishboneBus()
self.thisptr = new MatrixIOBus()
def __dealloc__(self):
del self.thisptr

def SpiInit(self):
return self.thisptr.SpiInit()
def Init(self):
return self.thisptr.Init()

def SpiRead(self, add, PyReadData data):
return self.thisptr.SpiRead(add, data.data, data.size)

def SpiClose(self):
self.thisptr.SpiClose()

def GetFPGAFrequency(self):
return self.thisptr.GetFPGAFrequency()
def Read(self, add, PyReadData data):
return self.thisptr.Read(add, data.data, data.size)

def FPGAClock(self):
return self.thisptr.FPGAClock()

def MatrixName(self):
return self.thisptr.MatrixName()

def MatrixVersion(self):
return self.thisptr.MatrixVersion()

def MatrixLeds(self):
return self.thisptr.MatrixLeds()

cdef class PyMatrixDriver:
cdef MatrixDriver *driverptr
def __cinit__(self):
Expand All @@ -162,7 +167,7 @@ cdef class PyMatrixDriver:
if type(self) is PyMatrixDriver:
del self.driverptr

def Setup(self, PyWishboneBus bus):
def Setup(self, PyMatrixIOBus bus):
self.driverptr.Setup(bus.thisptr)


Expand Down Expand Up @@ -423,7 +428,7 @@ cdef class PyGPIOControl:
def __dealloc__(self):
del self.thisptr

def Setup(self, PyWishboneBus bus):
def Setup(self, PyMatrixIOBus bus):
self.thisptr.Setup(bus.thisptr)

def SetMode(self, pin, mode):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

setup(
name='python-matrixio-hal',
version='1.0.1',
version='1.1.0',
description='Python HAL for the Matrix Creator / Voice wrapping the C++ drivers',
author='cmetz',
author_email='christoph.metz@gulp.de',
Expand Down

0 comments on commit 00098de

Please sign in to comment.