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

Eeprom todo added #208

Merged
merged 10 commits into from
Dec 22, 2022
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 1 addition & 1 deletion src/edgepi/adc/edgepi_adc.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def __init__(
# Load eeprom data and generate dictionary of calibration dataclass
eeprom = EdgePiEEPROM()
eeprom_data = eeprom.get_edgepi_reserved_data()
self.adc_calib_params = eeprom_data.adc_calib_parms
self.adc_calib_params = eeprom_data.adc_calib_params

self.adc_ops = ADCCommands()
self.gpio = EdgePiGPIO()
Expand Down
18 changes: 5 additions & 13 deletions src/edgepi/calibration/edgepi_eeprom.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
from edgepi.calibration.eeprom_constants import (
EEPROMInfo,
EdgePiMemoryInfo,
MessageFieldNumber,
EdgePiEEPROMData)
MessageFieldNumber
)
from edgepi.calibration.protobuf_mapping import EdgePiEEPROMData
from edgepi.calibration.eeprom_mapping_pb2 import EepromLayout
from edgepi.peripherals.i2c import I2CDevice

Expand Down Expand Up @@ -98,16 +99,7 @@ def get_edgepi_reserved_data(self):
"""
# pylint: disable=no-member
self.eeprom_layout.ParseFromString(self.__read_edgepi_reserved_memory())
eeprom_data = EdgePiEEPROMData()
eeprom_data.dac_calib_parms=eeprom_data.message_to_dict(self.eeprom_layout.dac)
eeprom_data.adc_calib_parms=eeprom_data.message_to_dict(self.eeprom_layout.adc)
eeprom_data.rtd_calib_parms=eeprom_data.message_to_dict(self.eeprom_layout.rtd)
eeprom_data.tc_calib_parms=eeprom_data.message_to_dict(self.eeprom_layout.tc)
eeprom_data.config_key=eeprom_data.keys_to_str(self.eeprom_layout.config_key)
eeprom_data.data_key=eeprom_data.keys_to_str(self.eeprom_layout.data_key)
eeprom_data.serial= self.eeprom_layout.serial_number
eeprom_data.model= self.eeprom_layout.model
eeprom_data.client_id= self.eeprom_layout.client_id
eeprom_data = EdgePiEEPROMData(self.eeprom_layout)
return eeprom_data

def sequential_read(self, mem_addr: int = None, length: int = None):
Expand All @@ -126,7 +118,7 @@ def sequential_read(self, mem_addr: int = None, length: int = None):
msg = self.set_read_msg(mem_addr_list, [0x00]*length)
self.log.debug(f'Reading Address {mem_addr}, {length} bytes, {msg[1].data}')
read_result = self.transfer(EEPROMInfo.DEV_ADDR.value, msg)
self.log.debug(f'Read data: {msg[1].data}')
# self.log.debug(f'Read data: {msg[1].data}') TODO: log number of bytes
return read_result


Expand Down
62 changes: 2 additions & 60 deletions src/edgepi/calibration/eeprom_constants.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
'''Address map of eeprom'''

from enum import Enum
from dataclasses import dataclass
from edgepi.calibration.eeprom_mapping_pb2 import EepromLayout
from edgepi.calibration.calibration_constants import CalibParam

class EEPROMInfo(Enum):
"""
Expand All @@ -28,6 +25,8 @@ class EdgePiMemoryInfo(Enum):
"""
USED_SPACE = 0x00
BUFF_START = 0x02
USER_SPACE_START = 0x100
USER_SPACE_END = 0x1FF

class MessageFieldNumber(Enum):
"""
Expand All @@ -43,60 +42,3 @@ class MessageFieldNumber(Enum):
SERIAL=7
MODEL=8
CLIENT_ID=9

@dataclass
class Keys:
"""
Dataclass to store key strings
"""
certificate: str = None
private: str = None

@dataclass
class EdgePiEEPROMData:
# pylint: disable=too-many-instance-attributes
"""
Dataclass to store edgepi reserved values
dac_calib_parms (dict): list of calibration parameters
adc_calib_parms (dict): list of calibration parameters
rtd_calib_parms (dict): list of calibration parameters
tc_calib_parms (dict): list of calibration parameters
config_key (Keys): dataclass
data_key (Keys): dataclass
serial (str)
model (str)
client_id (str)
"""
dac_calib_parms: dict = None
adc_calib_parms: dict = None
rtd_calib_parms: dict = None
tc_calib_parms: dict = None
config_key: Keys = None
data_key: Keys = None
serial: str = None
model: str = None
client_id: str = None

def message_to_dict(self, data_to_unpack: EepromLayout = None):
"""
Function to unpack message to list
Args:
data_to_unpack: EepromLayout message modules
Returns:
calib_list: 1-D array
"""
calib_dict={}
for indx, ch in enumerate(data_to_unpack.calibs):
calib_dict[indx] = CalibParam(gain=ch.gain,
offset=ch.offset)
return calib_dict

def keys_to_str(self, data_to_unpack: EepromLayout = None):
"""
Function to unpack message to string
Args:
data_to_unpack: EepromLayout message keys
Returns:
Keys (dataclass): keys values
"""
return Keys(certificate = data_to_unpack.certificate, private = data_to_unpack.private_key)
6 changes: 5 additions & 1 deletion src/edgepi/calibration/eeprom_mapping.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ syntax = "proto3";

message EepromLayout{
message ModuleCalibParams{
message ChannelCalib {
message ChannelCalib{
optional float gain = 1;
optional float offset = 2;
}
message HardwareValue{
optional float ref_resistor = 1;
}
repeated ChannelCalib calibs = 1;
repeated HardwareValue hw_val = 2;
}
message AwsKey{
string private_key = 1;
Expand Down
Loading