diff --git a/matrixio_hal/bus.py b/matrixio_hal/bus.py index 973b962..c3c6981 100644 --- a/matrixio_hal/bus.py +++ b/matrixio_hal/bus.py @@ -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() @@ -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': @@ -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() diff --git a/matrixio_hal/everloop.py b/matrixio_hal/everloop.py index 17c2b72..d653af8 100644 --- a/matrixio_hal/everloop.py +++ b/matrixio_hal/everloop.py @@ -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], diff --git a/matrixio_hal/matrixio_cpp_hal.pyx b/matrixio_hal/matrixio_cpp_hal.pyx index 1f85a8d..8bdd0e4 100644 --- a/matrixio_hal/matrixio_cpp_hal.pyx +++ b/matrixio_hal/matrixio_cpp_hal.pyx @@ -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: @@ -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) @@ -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): @@ -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) @@ -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): diff --git a/setup.py b/setup.py index 08a86d5..e48a5ed 100644 --- a/setup.py +++ b/setup.py @@ -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',