From 3579d57bcffd9b18ca2e0450e6ccb7bf5a25163b Mon Sep 17 00:00:00 2001 From: Merrick Rumel Date: Wed, 15 Jun 2022 16:05:24 -0400 Subject: [PATCH] Move files that code is in --- requirements.txt | 1 + setup.cfg | 2 +- src/TCAN4550-py/__init__.py | 113 -------------------------------- src/TCAN4550-py/tcan4550.py | 126 ++++++++++++++++++++++++++++++++++++ 4 files changed, 128 insertions(+), 114 deletions(-) create mode 100644 src/TCAN4550-py/tcan4550.py diff --git a/requirements.txt b/requirements.txt index ecf975e..daca773 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ +spidev -e . \ No newline at end of file diff --git a/setup.cfg b/setup.cfg index d23155e..d1111bc 100644 --- a/setup.cfg +++ b/setup.cfg @@ -15,7 +15,7 @@ package_dir = =src include_package_data = True install_requires = - + spidev [options.packages.find] where=src \ No newline at end of file diff --git a/src/TCAN4550-py/__init__.py b/src/TCAN4550-py/__init__.py index 7b8d42e..e69de29 100644 --- a/src/TCAN4550-py/__init__.py +++ b/src/TCAN4550-py/__init__.py @@ -1,113 +0,0 @@ -import ctypes -uint8_t = ctypes.c_uint8 -uint32_t = ctypes.c_uint32 - -class TCAN4550: - - def __init__(self) -> None: - - self.dev_ie = TCAN4550_device_interrupt_enable() - self.dev_ie = 0x0 - # Begin by clearing any potential SPI errors - self.TCAN_clearSPIerr() - - self.TCAN_configure_interrupt_enable(self.dev_ie) - - - def TCAN_clearSPIerr(self) -> None: - pass - - def TCAN_configure_interrupt_enable(self, ie) -> bool: - return True - - - - - - - - - - - -class TCAN4550_device_interrupt_enable_bits(ctypes.LittleEndianStructure): - _fields_ = [ - # @brief DEV_IE[0:7] : RESERVED - ("RESERVED1", uint8_t , 8), - - # @brief DEV_IE[8] : CANDOM, Can bus stuck dominant - ("CANDOMEN", uint8_t , 1), - - # @brief DEV_IE[9] : RESERVED - ("RESERVED2", uint8_t , 1), - - # @brief DEV_IE[10] : CANTO, CAN Timeout - ("CANTOEN", uint8_t , 1), - - # @brief DEV_IE[11] : RESERVED - ("RESERVED3", uint8_t , 1), - - # @brief DEV_IE[12] : FRAME_OVF, Frame Error Overflow (If Selective Wake is equipped) - ("FRAME_OVFEN", uint8_t , 1), - - # @brief DEV_IE[13] : WKERR, Wake Error - ("WKERREN", uint8_t , 1), - - # @brief DEV_IE[14] : LWU, Local Wake Up - ("LWUEN", uint8_t , 1), - - # @brief DEV_IE[15] : CANINT, CAN Bus Wake Up Interrupt - ("CANINTEN", uint8_t , 1), - - # @brief DEV_IE[16] : ECCERR, MRAM ECC Error - ("ECCERREN", uint8_t , 1), - - # @brief DEV_IE[17] : Reserved - ("RESERVED4", uint8_t , 1), - - # @brief DEV_IE[18] : WDTO, Watchdog Time Out - ("WDTOEN", uint8_t , 1), - - # @brief DEV_IE[19] : TSD, Thermal Shut Down - ("TSDEN", uint8_t , 1), - - # @brief DEV_IE[20] : PWRON, Power On Interrupt - ("PWRONEN", uint8_t , 1), - - # @brief DEV_IE[21] : UVIO, Undervoltage on UVIO - ("UVIOEN", uint8_t , 1), - - # @brief DEV_IE[22] : UVSUP, Undervoltage on VSUP and VCCOUT - ("UVSUPEN", uint8_t , 1), - - # @brief DEV_IE[23] : SMS, Sleep Mode Status Flag. Set when sleep mode is entered due to WKERR, UVIO, or TSD faults - ("SMSEN", uint8_t , 1), - - # @brief DEV_IE[24] : CANBUSBAT, CAN Shorted to VBAT - ("CANBUSBATEN", uint8_t , 1), - - # @brief DEV_IE[25] : CANBUSGND, CAN Shorted to GND - ("CANBUSGNDEN", uint8_t , 1), - - # @brief DEV_IE[26] : CANBUSOPEN, CAN Open fault - ("CANBUSOPENEN", uint8_t , 1), - - # @brief DEV_IE[27] : CANLGND, CANL GND - ("CANLGNDEN", uint8_t , 1), - - # @brief DEV_IE[28] : CANHBAT, CANH to VBAT - ("CANHBATEN", uint8_t , 1), - - # @brief DEV_IE[29] : CANHCANL, CANH and CANL shorted - ("CANHCANLEN", uint8_t , 1), - - # @brief DEV_IE[30] : CANBUSTERMOPEN, CAN Bus has termination point open - ("CANBUSTERMOPENEN", uint8_t , 1), - - # @brief DEV_IE[31] : CANBUSNOM, CAN Bus is normal flag - ("CANBUSNORMEN", uint8_t , 1) - ] - -class TCAN4550_device_interrupt_enable(ctypes.Union): - _fields_ = [("b", TCAN4550_device_interrupt_enable_bits), - ("word", uint32_t)] \ No newline at end of file diff --git a/src/TCAN4550-py/tcan4550.py b/src/TCAN4550-py/tcan4550.py new file mode 100644 index 0000000..89bd607 --- /dev/null +++ b/src/TCAN4550-py/tcan4550.py @@ -0,0 +1,126 @@ +import ctypes +uint8_t = ctypes.c_uint8 +uint32_t = ctypes.c_uint32 + +class TCAN4550: + + def __init__(self) -> None: + + self.dev_ie = TCAN4550_device_interrupt_enable() + self.dev_ie = 0x0 + # Begin by clearing any potential SPI errors + self.TCAN_clearSPIerr() + + self.TCAN_configure_interrupt_enable(self.dev_ie) + + + def TCAN_clearSPIerr(self) -> None: + pass + + def TCAN_configure_interrupt_enable(self, ie) -> bool: + return True + + def TCAN_write_32(self, address, data) -> None: + pass + + def TCAN_write_word(self, data, address, no_words) -> None: + pass + + + def TCAN_read_32(self, address, data) -> uint32_t: + return 0 + + def TCAN_read(self,address, data, no_words) -> uint32_t: + return 0 + + + + + + + + + + + +class TCAN4550_device_interrupt_enable_bits(ctypes.LittleEndianStructure): + _fields_ = [ + # @brief DEV_IE[0:7] : RESERVED + ("RESERVED1", uint8_t , 8), + + # @brief DEV_IE[8] : CANDOM, Can bus stuck dominant + ("CANDOMEN", uint8_t , 1), + + # @brief DEV_IE[9] : RESERVED + ("RESERVED2", uint8_t , 1), + + # @brief DEV_IE[10] : CANTO, CAN Timeout + ("CANTOEN", uint8_t , 1), + + # @brief DEV_IE[11] : RESERVED + ("RESERVED3", uint8_t , 1), + + # @brief DEV_IE[12] : FRAME_OVF, Frame Error Overflow (If Selective Wake is equipped) + ("FRAME_OVFEN", uint8_t , 1), + + # @brief DEV_IE[13] : WKERR, Wake Error + ("WKERREN", uint8_t , 1), + + # @brief DEV_IE[14] : LWU, Local Wake Up + ("LWUEN", uint8_t , 1), + + # @brief DEV_IE[15] : CANINT, CAN Bus Wake Up Interrupt + ("CANINTEN", uint8_t , 1), + + # @brief DEV_IE[16] : ECCERR, MRAM ECC Error + ("ECCERREN", uint8_t , 1), + + # @brief DEV_IE[17] : Reserved + ("RESERVED4", uint8_t , 1), + + # @brief DEV_IE[18] : WDTO, Watchdog Time Out + ("WDTOEN", uint8_t , 1), + + # @brief DEV_IE[19] : TSD, Thermal Shut Down + ("TSDEN", uint8_t , 1), + + # @brief DEV_IE[20] : PWRON, Power On Interrupt + ("PWRONEN", uint8_t , 1), + + # @brief DEV_IE[21] : UVIO, Undervoltage on UVIO + ("UVIOEN", uint8_t , 1), + + # @brief DEV_IE[22] : UVSUP, Undervoltage on VSUP and VCCOUT + ("UVSUPEN", uint8_t , 1), + + # @brief DEV_IE[23] : SMS, Sleep Mode Status Flag. Set when sleep mode is entered due to WKERR, UVIO, or TSD faults + ("SMSEN", uint8_t , 1), + + # @brief DEV_IE[24] : CANBUSBAT, CAN Shorted to VBAT + ("CANBUSBATEN", uint8_t , 1), + + # @brief DEV_IE[25] : CANBUSGND, CAN Shorted to GND + ("CANBUSGNDEN", uint8_t , 1), + + # @brief DEV_IE[26] : CANBUSOPEN, CAN Open fault + ("CANBUSOPENEN", uint8_t , 1), + + # @brief DEV_IE[27] : CANLGND, CANL GND + ("CANLGNDEN", uint8_t , 1), + + # @brief DEV_IE[28] : CANHBAT, CANH to VBAT + ("CANHBATEN", uint8_t , 1), + + # @brief DEV_IE[29] : CANHCANL, CANH and CANL shorted + ("CANHCANLEN", uint8_t , 1), + + # @brief DEV_IE[30] : CANBUSTERMOPEN, CAN Bus has termination point open + ("CANBUSTERMOPENEN", uint8_t , 1), + + # @brief DEV_IE[31] : CANBUSNOM, CAN Bus is normal flag + ("CANBUSNORMEN", uint8_t , 1) + ] + +class TCAN4550_device_interrupt_enable(ctypes.Union): + _fields_ = [("b", TCAN4550_device_interrupt_enable_bits), + ("word", uint32_t)] \ No newline at end of file