Skip to content

Commit

Permalink
Merge pull request #70 from tweedegolf/better-categories-and-boards
Browse files Browse the repository at this point in the history
Rework categories and boards
  • Loading branch information
tdittr authored Nov 1, 2024
2 parents 00b495e + 9efb105 commit 35a5fc8
Show file tree
Hide file tree
Showing 21 changed files with 704 additions and 273 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ db-dump.tar.gz
db-dump*
full-crate-db.json
full-crate-db-schema.json
driver-db-schema.json
10 changes: 10 additions & 0 deletions .taplo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,13 @@ include = [".taplo.toml", "driver-db/*.toml"]

[formatting]
indent_string = " "

[[rule]]
include = ["driver-db/*.toml"]

[rule.schema]
path = "driver-db-schema.json"

[rule.formatting]
reorder_arrays = true
reorder_keys = true
7 changes: 2 additions & 5 deletions backend/src/bin/read-driver-db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,8 @@ fn read_all(dir: &Path) -> anyhow::Result<HashMap<String, Driver>> {
}

pub fn parse_crate(path: &Path) -> anyhow::Result<(String, Driver)> {
if !path
.extension()
.is_some_and(|ext| ext == OsStr::new("toml"))
{
bail!("Driver info has wrong exctension: {path:?}");
if path.extension().is_none_or(|ext| ext != OsStr::new("toml")) {
bail!("Driver info has wrong extension: {path:?}");
}

let Some(crate_name) = path.file_stem() else {
Expand Down
2 changes: 1 addition & 1 deletion backend/src/description.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ mod spdx_expression_serde {
}

struct ExpressionVisitor;
impl<'de> serde::de::Visitor<'de> for ExpressionVisitor {
impl serde::de::Visitor<'_> for ExpressionVisitor {
type Value = Expression;

fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
Expand Down
60 changes: 23 additions & 37 deletions backend/src/driver_db.rs
Original file line number Diff line number Diff line change
@@ -1,80 +1,62 @@
use boards::DevBoard;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use url::Url;

pub mod boards;
pub mod categories;
pub mod manufacturers;
pub mod packages;

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(deny_unknown_fields)]
pub struct Driver {
/// Version of this driver description TOML schema
pub manifest_version: semver::Version,
/// Metadata about the driver
pub meta: Meta,
#[serde(skip_serializing_if = "DevBoards::is_empty", default)]
pub dev_boards: DevBoards,
/// List of development boards that house this chip
#[serde(skip_serializing_if = "Vec::is_empty", default)]
pub dev_boards: Vec<DevBoard>,
/// Interfaces used by this chip
#[serde(skip_serializing_if = "Interfaces::is_empty", default)]
pub interfaces: Interfaces,
/// Blog articles and similar covering this driver and its usage
#[serde(skip_serializing_if = "Vec::is_empty", default)]
pub resources: Vec<Resource>,
}

#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize, JsonSchema)]
#[serde(deny_unknown_fields)]
pub struct Meta {
/// Names of the chips this driver supports
pub names: Vec<String>,
pub manufacturer: manufacturers::Manufacturer,
/// Manufacturer that produces devices supported by this driver
pub manufacturer: manufacturers::ChipManufacturer,
/// Links to datasheets of chips that are supported by this driver
#[serde(skip_serializing_if = "Vec::is_empty", default)]
pub datasheets: Vec<Url>,
/// Functionalities this driver provides
#[serde(skip_serializing_if = "Vec::is_empty", default)]
pub categories: Vec<categories::Category>,
/// Part numbers of chips this driver supports
#[serde(skip_serializing_if = "Vec::is_empty", default)]
pub part_numbers: Vec<String>,
/// Names of KiCAD symbold for chips this driver supports
#[serde(skip_serializing_if = "Vec::is_empty", default)]
pub kicad_symbol: Vec<String>,
/// Packages or footprints in which chips are available
#[serde(skip_serializing_if = "Vec::is_empty", default)]
pub packages: Vec<packages::Package>,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(deny_unknown_fields)]
pub struct DevBoards {
#[serde(skip_serializing_if = "Option::is_none", default)]
pub adafruit: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none", default)]
pub sparkfun: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none", default)]
pub mikroe: Option<u32>,
#[serde(skip_serializing_if = "Vec::is_empty", default)]
pub other: Vec<GenericDevBoard>,
}

impl DevBoards {
pub fn is_empty(&self) -> bool {
matches!(
self,
DevBoards {
adafruit: None,
sparkfun: None,
mikroe: None,
other: _,
}
) && self.other.is_empty()
}
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(deny_unknown_fields)]
pub struct GenericDevBoard {
pub name: String,
pub link: url::Url,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(deny_unknown_fields)]
pub struct Interfaces {
/// Information about the I2C interface (if present)
#[serde(skip_serializing_if = "Option::is_none", default)]
pub i2c: Option<I2c>,
/// Information about the SPI interface (if present)
#[serde(skip_serializing_if = "Option::is_none", default)]
pub spi: Option<Spi>,
}
Expand All @@ -94,14 +76,18 @@ impl Interfaces {
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(deny_unknown_fields)]
pub struct I2c {
/// Addresses that can be used by this device
pub addrs: Vec<u8>,
/// Does this device have an interrupt line?
pub interrupt: bool,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(deny_unknown_fields)]
pub struct Spi {
/// Whether this device can be used on a shared bus or only on an exclusive device
pub bus_type: SpiDeviceType,
/// Does this device have an interrupt line?
pub interrupt: bool,
}

Expand Down
26 changes: 26 additions & 0 deletions backend/src/driver_db/boards.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use url::Url;

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct DevBoard {
name: String,
manufacturer: BoardManufacturer,
link: Url,
connections: Vec<Connection>,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
pub enum BoardManufacturer {
Adafruit,
Sparkfun,
Mikroe,
#[serde(rename = "BBC")]
Bbc,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
pub enum Connection {
StemmaQt,
MikroBus,
}
Loading

0 comments on commit 35a5fc8

Please sign in to comment.