Replaced constants with PHP enums in TDF scripts. Updated PHP version in dependency list in the README
This commit is contained in:
@@ -80,7 +80,7 @@ repositories.
|
||||
- libhidapi (0.11.2 or later) (`libhidapi-dev`)
|
||||
- yaml-cpp (version 0.7.0 or later) (`libyaml-cpp-dev`)
|
||||
- libprocps (`libprocps-dev`)
|
||||
- PHP CLI version 8 or later, with the xml extension (`php8.0-cli`, `php8.0-xml`)
|
||||
- PHP CLI version 8.2 or later, with the xml extension (`php8.2-cli`, `php8.2-xml`)
|
||||
- Qt Version 6.2.4 or later (see note below)
|
||||
|
||||
When installing Qt, it's best to install via the Qt installer: https://www.qt.io/download
|
||||
|
||||
@@ -7,6 +7,8 @@ use Bloom\BuildScripts\TargetDescriptionFiles\Register;
|
||||
use Bloom\BuildScripts\TargetDescriptionFiles\TargetDescriptionFile;
|
||||
|
||||
require_once __DIR__ . "/../TargetDescriptionFile.php";
|
||||
require_once __DIR__ . "/AvrFamily.php";
|
||||
require_once __DIR__ . "/AvrPhysicalInterface.php";
|
||||
require_once __DIR__ . "/Signature.php";
|
||||
require_once __DIR__ . "/TargetParameters.php";
|
||||
require_once __DIR__ . "/DebugWireParameters.php";
|
||||
@@ -18,21 +20,6 @@ require_once __DIR__ . "/FuseBitsDescriptor.php";
|
||||
|
||||
class Avr8TargetDescriptionFile extends TargetDescriptionFile
|
||||
{
|
||||
const AVR8_FAMILY_MEGA = 'MEGA';
|
||||
const AVR8_FAMILY_TINY = 'TINY';
|
||||
const AVR8_FAMILY_XMEGA = 'XMEGA';
|
||||
const AVR8_FAMILY_DB = 'DB';
|
||||
const AVR8_FAMILY_DA = 'DA';
|
||||
const AVR8_FAMILY_DD = 'DD';
|
||||
const AVR8_FAMILY_EA = 'EA';
|
||||
const AVR8_FAMILY_OTHER = 'OTHER';
|
||||
|
||||
const AVR8_PHYSICAL_INTERFACE_ISP = 'ISP';
|
||||
const AVR8_PHYSICAL_INTERFACE_JTAG = 'JTAG';
|
||||
const AVR8_PHYSICAL_INTERFACE_PDI = 'PDI';
|
||||
const AVR8_PHYSICAL_INTERFACE_UPDI = 'UPDI';
|
||||
const AVR8_PHYSICAL_INTERFACE_DEBUG_WIRE = 'DEBUG_WIRE';
|
||||
|
||||
public function getSignature(): ?Signature
|
||||
{
|
||||
$byteZero = $this->getPropertyValue('signatures', 'signature0');
|
||||
@@ -51,43 +38,43 @@ class Avr8TargetDescriptionFile extends TargetDescriptionFile
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getAvrFamily(): ?string
|
||||
public function getAvrFamily(): ?AvrFamily
|
||||
{
|
||||
if (!empty($this->deviceAttributesByName['avr-family'])) {
|
||||
if (stristr($this->deviceAttributesByName['avr-family'], 'xmega') !== false) {
|
||||
return self::AVR8_FAMILY_XMEGA;
|
||||
return AvrFamily::XMEGA;
|
||||
|
||||
} else if (stristr($this->deviceAttributesByName['avr-family'], 'tiny') !== false) {
|
||||
return self::AVR8_FAMILY_TINY;
|
||||
return AvrFamily::TINY;
|
||||
|
||||
} else if (stristr($this->deviceAttributesByName['avr-family'], 'mega') !== false) {
|
||||
return self::AVR8_FAMILY_MEGA;
|
||||
return AvrFamily::MEGA;
|
||||
|
||||
} else if (strtolower(trim($this->deviceAttributesByName['avr-family'])) == 'avr da') {
|
||||
return self::AVR8_FAMILY_DA;
|
||||
return AvrFamily::DA;
|
||||
|
||||
} else if (strtolower(trim($this->deviceAttributesByName['avr-family'])) == 'avr db') {
|
||||
return self::AVR8_FAMILY_DB;
|
||||
return AvrFamily::DB;
|
||||
|
||||
} else if (strtolower(trim($this->deviceAttributesByName['avr-family'])) == 'avr dd') {
|
||||
return self::AVR8_FAMILY_DD;
|
||||
return AvrFamily::DD;
|
||||
|
||||
} else if (strtolower(trim($this->deviceAttributesByName['avr-family'])) == 'avr ea') {
|
||||
return self::AVR8_FAMILY_EA;
|
||||
return AvrFamily::EA;
|
||||
}
|
||||
}
|
||||
|
||||
return self::AVR8_FAMILY_OTHER;
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getSupportedPhysicalInterfaces(): array
|
||||
{
|
||||
$physicalInterfacesByName = [
|
||||
'isp' => self::AVR8_PHYSICAL_INTERFACE_ISP,
|
||||
'debugwire' => self::AVR8_PHYSICAL_INTERFACE_DEBUG_WIRE,
|
||||
'updi' => self::AVR8_PHYSICAL_INTERFACE_UPDI,
|
||||
'pdi' => self::AVR8_PHYSICAL_INTERFACE_PDI,
|
||||
'jtag' => self::AVR8_PHYSICAL_INTERFACE_JTAG,
|
||||
'isp' => AvrPhysicalInterface::ISP,
|
||||
'debugwire' => AvrPhysicalInterface::DEBUG_WIRE,
|
||||
'updi' => AvrPhysicalInterface::UPDI,
|
||||
'pdi' => AvrPhysicalInterface::PDI,
|
||||
'jtag' => AvrPhysicalInterface::JTAG,
|
||||
];
|
||||
|
||||
return array_filter(
|
||||
@@ -102,10 +89,10 @@ class Avr8TargetDescriptionFile extends TargetDescriptionFile
|
||||
public function getSupportedDebugPhysicalInterfaces(): array
|
||||
{
|
||||
$physicalInterfacesByName = [
|
||||
'debugwire' => self::AVR8_PHYSICAL_INTERFACE_DEBUG_WIRE,
|
||||
'updi' => self::AVR8_PHYSICAL_INTERFACE_UPDI,
|
||||
'pdi' => self::AVR8_PHYSICAL_INTERFACE_PDI,
|
||||
'jtag' => self::AVR8_PHYSICAL_INTERFACE_JTAG,
|
||||
'debugwire' => AvrPhysicalInterface::DEBUG_WIRE,
|
||||
'updi' => AvrPhysicalInterface::UPDI,
|
||||
'pdi' => AvrPhysicalInterface::PDI,
|
||||
'jtag' => AvrPhysicalInterface::JTAG,
|
||||
];
|
||||
|
||||
return array_filter(
|
||||
@@ -592,7 +579,7 @@ class Avr8TargetDescriptionFile extends TargetDescriptionFile
|
||||
}
|
||||
|
||||
$family = $this->getAvrFamily();
|
||||
if (is_null($family) || $family == self::AVR8_FAMILY_OTHER) {
|
||||
if (is_null($family)) {
|
||||
$failures[] = 'Unknown AVR8 family';
|
||||
}
|
||||
|
||||
@@ -665,7 +652,7 @@ class Avr8TargetDescriptionFile extends TargetDescriptionFile
|
||||
$failures[] = 'Missing eeprom start address.';
|
||||
}
|
||||
|
||||
if (in_array(self::AVR8_PHYSICAL_INTERFACE_DEBUG_WIRE, $debugPhysicalInterfaces)) {
|
||||
if (in_array(AvrPhysicalInterface::DEBUG_WIRE, $debugPhysicalInterfaces)) {
|
||||
$debugWireParameters = $this->getDebugWireParameters();
|
||||
$ispParameters = $this->getIspParameters();
|
||||
|
||||
@@ -685,7 +672,7 @@ class Avr8TargetDescriptionFile extends TargetDescriptionFile
|
||||
$failures[] = 'Missing oscillator calibration register address.';
|
||||
}
|
||||
|
||||
if (!in_array(self::AVR8_PHYSICAL_INTERFACE_ISP, $physicalInterfaces)) {
|
||||
if (!in_array(AvrPhysicalInterface::ISP, $physicalInterfaces)) {
|
||||
$failures[] = 'Missing ISP interface for debugWire target.';
|
||||
}
|
||||
|
||||
@@ -755,8 +742,8 @@ class Avr8TargetDescriptionFile extends TargetDescriptionFile
|
||||
}
|
||||
|
||||
if (
|
||||
in_array(self::AVR8_PHYSICAL_INTERFACE_JTAG, $debugPhysicalInterfaces)
|
||||
&& $family == self::AVR8_FAMILY_MEGA
|
||||
in_array(AvrPhysicalInterface::JTAG, $debugPhysicalInterfaces)
|
||||
&& $family == AvrFamily::MEGA
|
||||
) {
|
||||
$jtagParameters = $this->getJtagParameters();
|
||||
|
||||
@@ -785,7 +772,7 @@ class Avr8TargetDescriptionFile extends TargetDescriptionFile
|
||||
}
|
||||
}
|
||||
|
||||
if (in_array(self::AVR8_PHYSICAL_INTERFACE_PDI, $debugPhysicalInterfaces)) {
|
||||
if (in_array(AvrPhysicalInterface::PDI, $debugPhysicalInterfaces)) {
|
||||
$pdiParameters = $this->getPdiParameters();
|
||||
|
||||
if (is_null($pdiParameters->appSectionPdiOffset)) {
|
||||
@@ -833,7 +820,7 @@ class Avr8TargetDescriptionFile extends TargetDescriptionFile
|
||||
}
|
||||
}
|
||||
|
||||
if (in_array(Avr8TargetDescriptionFile::AVR8_PHYSICAL_INTERFACE_UPDI, $debugPhysicalInterfaces)) {
|
||||
if (in_array(AvrPhysicalInterface::UPDI, $debugPhysicalInterfaces)) {
|
||||
$updiParameters = $this->getUpdiParameters();
|
||||
if (is_null($updiParameters->nvmModuleBaseAddress)) {
|
||||
$failures[] = 'Missing NVM base address.';
|
||||
@@ -879,8 +866,8 @@ class Avr8TargetDescriptionFile extends TargetDescriptionFile
|
||||
}
|
||||
|
||||
if (
|
||||
in_array(Avr8TargetDescriptionFile::AVR8_PHYSICAL_INTERFACE_JTAG, $debugPhysicalInterfaces)
|
||||
|| in_array(Avr8TargetDescriptionFile::AVR8_PHYSICAL_INTERFACE_UPDI, $debugPhysicalInterfaces)
|
||||
in_array(AvrPhysicalInterface::JTAG, $debugPhysicalInterfaces)
|
||||
|| in_array(AvrPhysicalInterface::UPDI, $debugPhysicalInterfaces)
|
||||
) {
|
||||
if (empty($this->getFuseBitsDescriptor('eesave'))) {
|
||||
$failures[] = 'Could not find EESAVE fuse bit field for JTAG/UPDI target.';
|
||||
|
||||
13
build/scripts/TargetDescriptionFiles/AVR8/AvrFamily.php
Normal file
13
build/scripts/TargetDescriptionFiles/AVR8/AvrFamily.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
namespace Bloom\BuildScripts\TargetDescriptionFiles\Avr8;
|
||||
|
||||
enum AvrFamily: string
|
||||
{
|
||||
case MEGA = 'MEGA';
|
||||
case TINY = 'TINY';
|
||||
case XMEGA = 'XMEGA';
|
||||
case DB = 'DB';
|
||||
case DA = 'DA';
|
||||
case DD = 'DD';
|
||||
case EA = 'EA';
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
namespace Bloom\BuildScripts\TargetDescriptionFiles\Avr8;
|
||||
|
||||
enum AvrPhysicalInterface: string
|
||||
{
|
||||
case ISP = 'ISP';
|
||||
case JTAG = 'JTAG';
|
||||
case PDI = 'PDI';
|
||||
case UPDI = 'UPDI';
|
||||
case DEBUG_WIRE = 'DEBUG_WIRE';
|
||||
}
|
||||
@@ -1,20 +1,14 @@
|
||||
<?php
|
||||
namespace Bloom\BuildScripts\TargetDescriptionFiles;
|
||||
|
||||
require_once __DIR__ . "/PinoutType.php";
|
||||
require_once __DIR__ . "/Pin.php";
|
||||
|
||||
class Pinout
|
||||
{
|
||||
const TYPE_SOIC = 'SOIC';
|
||||
const TYPE_SSOP = 'SSOP';
|
||||
const TYPE_DIP = 'DIP';
|
||||
const TYPE_QFN = 'QFN';
|
||||
const TYPE_QFP = 'QFP';
|
||||
const TYPE_BGA = 'BGA';
|
||||
|
||||
public ?string $name = null;
|
||||
public ?string $function = null;
|
||||
public ?string $type = null;
|
||||
public ?PinoutType $type = null;
|
||||
|
||||
/**
|
||||
* The name of the pinouts typically include the number of pins. We extract this if we can, so that we can
|
||||
|
||||
12
build/scripts/TargetDescriptionFiles/PinoutType.php
Normal file
12
build/scripts/TargetDescriptionFiles/PinoutType.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
namespace Bloom\BuildScripts\TargetDescriptionFiles;
|
||||
|
||||
enum PinoutType: string
|
||||
{
|
||||
case SOIC = 'SOIC';
|
||||
case SSOP = 'SSOP';
|
||||
case DIP = 'DIP';
|
||||
case QFN = 'QFN';
|
||||
case QFP = 'QFP';
|
||||
case BGA = 'BGA';
|
||||
}
|
||||
@@ -439,25 +439,7 @@ class TargetDescriptionFile
|
||||
|
||||
$pinout->name = isset($pinoutAttrs['name']) ? $pinoutAttrs['name'] : null;
|
||||
$pinout->function = isset($pinoutAttrs['function']) ? $pinoutAttrs['function'] : null;
|
||||
|
||||
if (stristr($pinout->name, Pinout::TYPE_DIP) !== false) {
|
||||
$pinout->type = Pinout::TYPE_DIP;
|
||||
|
||||
} else if (stristr($pinout->name, Pinout::TYPE_SOIC) !== false) {
|
||||
$pinout->type = Pinout::TYPE_SOIC;
|
||||
|
||||
} else if (stristr($pinout->name, Pinout::TYPE_SSOP) !== false) {
|
||||
$pinout->type = Pinout::TYPE_SSOP;
|
||||
|
||||
} else if (stristr($pinout->name, Pinout::TYPE_QFN) !== false) {
|
||||
$pinout->type = Pinout::TYPE_QFN;
|
||||
|
||||
} else if (stristr($pinout->name, Pinout::TYPE_QFP) !== false) {
|
||||
$pinout->type = Pinout::TYPE_QFP;
|
||||
|
||||
} else if (stristr($pinout->name, Pinout::TYPE_BGA) !== false) {
|
||||
$pinout->type = Pinout::TYPE_BGA;
|
||||
}
|
||||
$pinout->type = PinoutType::tryFrom($pinout->name);
|
||||
|
||||
// Attempt to extract the number of expected pins for this pinout, from the pinout name
|
||||
$expectedPinCount = filter_var($pinout->name, FILTER_SANITIZE_NUMBER_INT);
|
||||
@@ -531,7 +513,7 @@ class TargetDescriptionFile
|
||||
$failures[] = 'Could not deduce expected pin count for pinout "' . $pinout->name . '"';
|
||||
}
|
||||
|
||||
if (in_array($pinout->type, [Pinout::TYPE_DIP, Pinout::TYPE_QFN, Pinout::TYPE_SOIC])) {
|
||||
if (in_array($pinout->type, [PinoutType::DIP, PinoutType::QFN, PinoutType::SOIC])) {
|
||||
foreach ($pinout->pins as $index => $pin) {
|
||||
if (is_null($pin->position)) {
|
||||
$failures[] = 'Missing/invalid pin position for pin (index: ' . $index . ').';
|
||||
@@ -543,13 +525,14 @@ class TargetDescriptionFile
|
||||
}
|
||||
}
|
||||
|
||||
if (in_array($pinout->type, [Pinout::TYPE_SOIC, Pinout::TYPE_DIP, Pinout::TYPE_SSOP])
|
||||
if (
|
||||
in_array($pinout->type, [PinoutType::SOIC, PinoutType::DIP, PinoutType::SSOP])
|
||||
&& count($pinout->pins) % 2 != 0
|
||||
) {
|
||||
$failures[] = 'DIP/SOIC/SSOP pinout (' . $pinout->name . ') pin count is not a multiple of two.';
|
||||
}
|
||||
|
||||
if (in_array($pinout->type, [Pinout::TYPE_QFN, Pinout::TYPE_QFP]) && count($pinout->pins) % 4 != 0) {
|
||||
if (in_array($pinout->type, [PinoutType::QFN, PinoutType::QFP]) && count($pinout->pins) % 4 != 0) {
|
||||
$failures[] = 'QFP/QFN pinout (' . $pinout->name . ') pin count is not a multiple of four.';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user