From cd5fbb551174c3095dc6c61bd0eedf5c2a56c2ed Mon Sep 17 00:00:00 2001 From: Joonas Javanainen Date: Fri, 25 Oct 2024 22:27:59 +0300 Subject: [PATCH] Use more nom parsers --- backend/src/config/cartridge.rs | 103 ++++--- backend/src/parser.rs | 379 +++++++++++++----------- backend/src/parser/accelerometer.rs | 82 +++--- backend/src/parser/agb_amp.rs | 50 ---- backend/src/parser/agb_pmic.rs | 88 ------ backend/src/parser/agb_reg.rs | 31 -- backend/src/parser/ags_charge_ctrl.rs | 36 +-- backend/src/parser/ags_pmic_new.rs | 32 --- backend/src/parser/ags_pmic_old.rs | 50 ---- backend/src/parser/amic.rs | 52 ++++ backend/src/parser/atmel.rs | 44 +++ backend/src/parser/bsi.rs | 134 +++++++++ backend/src/parser/cgb_reg.rs | 31 -- backend/src/parser/dmg_amp.rs | 32 --- backend/src/parser/dmg_reg.rs | 33 --- backend/src/parser/eeprom.rs | 101 +++---- backend/src/parser/flash.rs | 25 -- backend/src/parser/flash/tsop_i_32.rs | 132 --------- backend/src/parser/flash/tsop_i_40.rs | 35 --- backend/src/parser/fram.rs | 63 ---- backend/src/parser/fujitsu.rs | 112 ++++++++ backend/src/parser/gbs_reg.rs | 27 -- backend/src/parser/hex_inverter.rs | 27 -- backend/src/parser/hynix.rs | 99 +++++++ backend/src/parser/hyundai.rs | 131 +++++++++ backend/src/parser/lgs.rs | 124 ++++++++ backend/src/parser/line_decoder.rs | 33 --- backend/src/parser/macronix.rs | 381 +++++++++++++++++++++++++ backend/src/parser/mask_rom.rs | 359 +++++------------------ backend/src/parser/mgb_amp.rs | 50 ---- backend/src/parser/mgl_transformer.rs | 32 --- backend/src/parser/mitsubishi.rs | 30 ++ backend/src/parser/mitsumi.rs | 155 ++++++++++ backend/src/parser/nec.rs | 335 ++++++++++++++++++++++ backend/src/parser/oxy_pmic.rs | 31 -- backend/src/parser/oxy_u4.rs | 20 +- backend/src/parser/oxy_u5.rs | 23 +- backend/src/parser/rohm.rs | 179 ++++++++++++ backend/src/parser/rtc.rs | 113 -------- backend/src/parser/sanyo.rs | 111 +++++++ backend/src/parser/seiko.rs | 134 +++++++++ backend/src/parser/sharp.rs | 153 ++++++++++ backend/src/parser/sram.rs | 171 +++++------ backend/src/parser/sram/sop_28.rs | 325 +-------------------- backend/src/parser/sram/sop_32.rs | 34 --- backend/src/parser/sram/tsop_i_28.rs | 8 +- backend/src/parser/sram/tsop_i_48.rs | 249 ---------------- backend/src/parser/sst.rs | 38 +++ backend/src/parser/st_micro.rs | 54 ++++ backend/src/parser/supervisor_reset.rs | 177 ------------ backend/src/parser/tama.rs | 9 +- backend/src/parser/ti.rs | 36 +++ backend/src/parser/toshiba.rs | 204 +++++++++++++ backend/src/parser/victronix.rs | 34 +++ backend/src/parser/winbond.rs | 127 +++++++++ site/src/legacy/cartridge.rs | 13 +- site/src/main.rs | 72 ++--- site/src/process/part.rs | 67 ++--- 58 files changed, 3249 insertions(+), 2561 deletions(-) delete mode 100644 backend/src/parser/agb_amp.rs delete mode 100644 backend/src/parser/agb_pmic.rs delete mode 100644 backend/src/parser/agb_reg.rs delete mode 100644 backend/src/parser/ags_pmic_new.rs delete mode 100644 backend/src/parser/ags_pmic_old.rs create mode 100644 backend/src/parser/amic.rs create mode 100644 backend/src/parser/atmel.rs create mode 100644 backend/src/parser/bsi.rs delete mode 100644 backend/src/parser/cgb_reg.rs delete mode 100644 backend/src/parser/dmg_amp.rs delete mode 100644 backend/src/parser/dmg_reg.rs delete mode 100644 backend/src/parser/flash.rs delete mode 100644 backend/src/parser/flash/tsop_i_32.rs delete mode 100644 backend/src/parser/flash/tsop_i_40.rs delete mode 100644 backend/src/parser/fram.rs create mode 100644 backend/src/parser/fujitsu.rs delete mode 100644 backend/src/parser/gbs_reg.rs delete mode 100644 backend/src/parser/hex_inverter.rs create mode 100644 backend/src/parser/hynix.rs create mode 100644 backend/src/parser/hyundai.rs create mode 100644 backend/src/parser/lgs.rs delete mode 100644 backend/src/parser/line_decoder.rs create mode 100644 backend/src/parser/macronix.rs delete mode 100644 backend/src/parser/mgb_amp.rs delete mode 100644 backend/src/parser/mgl_transformer.rs create mode 100644 backend/src/parser/mitsubishi.rs create mode 100644 backend/src/parser/mitsumi.rs create mode 100644 backend/src/parser/nec.rs delete mode 100644 backend/src/parser/oxy_pmic.rs create mode 100644 backend/src/parser/rohm.rs delete mode 100644 backend/src/parser/rtc.rs create mode 100644 backend/src/parser/sanyo.rs create mode 100644 backend/src/parser/seiko.rs create mode 100644 backend/src/parser/sharp.rs delete mode 100644 backend/src/parser/sram/sop_32.rs delete mode 100644 backend/src/parser/sram/tsop_i_48.rs create mode 100644 backend/src/parser/sst.rs create mode 100644 backend/src/parser/st_micro.rs delete mode 100644 backend/src/parser/supervisor_reset.rs create mode 100644 backend/src/parser/ti.rs create mode 100644 backend/src/parser/toshiba.rs create mode 100644 backend/src/parser/victronix.rs create mode 100644 backend/src/parser/winbond.rs diff --git a/backend/src/config/cartridge.rs b/backend/src/config/cartridge.rs index 5083f34f1..4f36844a3 100644 --- a/backend/src/config/cartridge.rs +++ b/backend/src/config/cartridge.rs @@ -21,19 +21,16 @@ use crate::{ accelerometer::accelerometer, crystal_32kihz::crystal_32kihz, eeprom::eeprom, - flash::{flash_tsop_i_32, flash_tsop_i_40}, - fram::fram_sop_28, - hex_inverter::hex_inverter, - line_decoder::line_decoder, + flash_tsop_i_32_3v3, flash_tsop_i_40_5v, fram_sop_28_3v3, hex_inverter, line_decoder, mapper, mask_rom::{ agb_mask_rom_tsop_ii_44, mask_rom_glop_top_28, mask_rom_qfp_44, mask_rom_sop_32, - mask_rom_tsop_i_32, mask_rom_tsop_ii_44, + mask_rom_tsop_i_32, mask_rom_tsop_ii_44_5v, }, - rtc::{rtc_sop_20, rtc_sop_8}, - sram::{sram_sop_28, sram_sop_32, sram_tsop_i_28}, - supervisor_reset::supervisor_reset, - tama::tama, + rtc_sop_20, rtc_sop_8, + sram::{sram_sop_28_3v3, sram_sop_28_5v, sram_sop_32_5v, sram_tsop_i_28}, + supervisor_reset, + tama::{tama5, tama6, tama7}, unknown_chip, LabelParser, ParsedData, }, }; @@ -183,7 +180,7 @@ impl BoardConfig { // TSOP-II-44 ROM D::U1 => part(PartRole::Rom, agb_mask_rom_tsop_ii_44()), // SOP-28 FRAM - D::U2 => part(PartRole::Ram, fram_sop_28()), + D::U2 => part(PartRole::Ram, fram_sop_28_3v3()), _ => None, }, BoardConfig::AgbE01 => match designator { @@ -195,7 +192,7 @@ impl BoardConfig { // TSOP-II-44 ROM D::U1 => part(PartRole::Rom, agb_mask_rom_tsop_ii_44()), // TSOP-I-32 Flash - D::U2 => part(PartRole::Flash, flash_tsop_i_32()), + D::U2 => part(PartRole::Flash, flash_tsop_i_32_3v3()), _ => None, }, BoardConfig::AgbE03 => match designator { @@ -209,7 +206,7 @@ impl BoardConfig { // TSOP-II-44 ROM D::U1 => part(PartRole::Rom, agb_mask_rom_tsop_ii_44()), // TSOP-I-32 Flash - D::U2 => part(PartRole::Flash, flash_tsop_i_32()), + D::U2 => part(PartRole::Flash, flash_tsop_i_32_3v3()), // SOP-8 RTC D::U3 => part(PartRole::Rtc, rtc_sop_8()), D::X1 => part(PartRole::Crystal, crystal_32kihz()), @@ -219,7 +216,7 @@ impl BoardConfig { // TSOP-II-44 ROM D::U1 => part(PartRole::Rom, agb_mask_rom_tsop_ii_44()), // SOP-28 RAM - D::U2 => part(PartRole::Ram, sram_sop_28()), + D::U2 => part(PartRole::Ram, sram_sop_28_3v3()), // SOP-8 BU9803F D::U3 => part(PartRole::SupervisorReset, supervisor_reset()), _ => None, @@ -228,7 +225,7 @@ impl BoardConfig { // TSOP-II-44 ROM D::U1 => part(PartRole::Rom, agb_mask_rom_tsop_ii_44()), // SOP-28 FRAM - D::U2 => part(PartRole::Ram, fram_sop_28()), + D::U2 => part(PartRole::Ram, fram_sop_28_3v3()), _ => None, }, BoardConfig::AgbE12 => match designator { @@ -262,11 +259,11 @@ impl BoardConfig { }, BoardConfig::Tama => match designator { // SOP-32 TAMA7 - D::U1 => part(PartRole::Rom, tama()), + D::U1 => part(PartRole::Rom, tama7()), // SOP-28 TAMA5 - D::U2 => part(PartRole::Mapper, tama()), + D::U2 => part(PartRole::Mapper, tama5()), // SOP-28 TAMA6 - D::U3 => part(PartRole::Mcu, tama()), + D::U3 => part(PartRole::Mcu, tama6()), // SOP-20 D::U4 => part(PartRole::Rtc, rtc_sop_20()), // SOP-8 M62021P @@ -285,9 +282,9 @@ impl BoardConfig { // SOP-32 ROM D::U2 => part(PartRole::Rom, mask_rom_sop_32()), // TSOP-I-40 Flash - D::U3 => part(PartRole::Flash, flash_tsop_i_40()), + D::U3 => part(PartRole::Flash, flash_tsop_i_40_5v()), // SOP-28 RAM - D::U4 => part(PartRole::Ram, sram_sop_28()), + D::U4 => part(PartRole::Ram, sram_sop_28_5v()), // SOP-8 MM1134 D::U5 => part(PartRole::SupervisorReset, supervisor_reset()), _ => None, @@ -298,18 +295,18 @@ impl BoardConfig { // QFP-32 MBC5 D::U2 => part(PartRole::Mapper, mapper::mbc5_qfp32()), // SOP-28 RAM - D::U3 => part(PartRole::Ram, sram_sop_28()), + D::U3 => part(PartRole::Ram, sram_sop_28_5v()), // SOP-8 MM1134A D::U4 => part(PartRole::SupervisorReset, supervisor_reset()), _ => None, }, BoardConfig::DmgA03 | BoardConfig::DmgA08 => match designator { // TSOP-II-44 ROM - D::U1 => part(PartRole::Rom, mask_rom_tsop_ii_44()), + D::U1 => part(PartRole::Rom, mask_rom_tsop_ii_44_5v()), // QFP-32 MBC5 D::U2 => part(PartRole::Mapper, mapper::mbc5_qfp32()), // SOP-28 RAM - D::U3 => part(PartRole::Ram, sram_sop_28()), + D::U3 => part(PartRole::Ram, sram_sop_28_5v()), // SOP-8 MM1134A D::U4 => part(PartRole::SupervisorReset, supervisor_reset()), _ => None, @@ -320,7 +317,7 @@ impl BoardConfig { // QFP-32 MBC5 D::U2 => part(PartRole::Mapper, mapper::mbc5_qfp32()), // SOP-28 RAM - D::U3 => part(PartRole::Ram, sram_sop_28()), + D::U3 => part(PartRole::Ram, sram_sop_28_5v()), // SOP-8 MM1134A D::U4 => part(PartRole::SupervisorReset, supervisor_reset()), // MOT1 => motor @@ -332,7 +329,7 @@ impl BoardConfig { // QFP-32 MBC5 D::U2 => part(PartRole::Mapper, mapper::mbc5_qfp32()), // SOP-28 RAM - D::U3 => part(PartRole::Ram, sram_sop_28()), + D::U3 => part(PartRole::Ram, sram_sop_28_5v()), // SOP-8 MM1134A D::U4 => part(PartRole::SupervisorReset, supervisor_reset()), _ => None, @@ -346,18 +343,18 @@ impl BoardConfig { }, BoardConfig::DmgA09 => match designator { // TSOP-II-44 ROM - D::U1 => part(PartRole::Rom, mask_rom_tsop_ii_44()), + D::U1 => part(PartRole::Rom, mask_rom_tsop_ii_44_5v()), // QFP-32 MBC5 D::U2 => part(PartRole::Mapper, mapper::mbc5_qfp32()), _ => None, }, BoardConfig::DmgA11 => match designator { // TSOP-II-44 ROM - D::U1 => part(PartRole::Rom, mask_rom_tsop_ii_44()), + D::U1 => part(PartRole::Rom, mask_rom_tsop_ii_44_5v()), // QFP-32 MBC5 D::U2 => part(PartRole::Mapper, mapper::mbc5_qfp32()), // SOP-28 RAM - D::U3 => part(PartRole::Ram, sram_sop_28()), + D::U3 => part(PartRole::Ram, sram_sop_28_5v()), // SOP-8 MM1134A D::U4 => part(PartRole::SupervisorReset, supervisor_reset()), // MOT1 => motor @@ -365,26 +362,26 @@ impl BoardConfig { }, BoardConfig::DmgA14 => match designator { // TSOP-II-44 ROM - D::U1 => part(PartRole::Rom, mask_rom_tsop_ii_44()), + D::U1 => part(PartRole::Rom, mask_rom_tsop_ii_44_5v()), // QFP-32 MBC5 D::U2 => part(PartRole::Mapper, mapper::mbc5_qfp32()), // SOP-32 RAM - D::U3 => part(PartRole::Ram, sram_sop_32()), + D::U3 => part(PartRole::Ram, sram_sop_32_5v()), // SOP-8 MM1134A D::U4 => part(PartRole::SupervisorReset, supervisor_reset()), _ => None, }, BoardConfig::DmgA15 => match designator { // TSOP-II-44 ROM - D::U1 => part(PartRole::Rom, mask_rom_tsop_ii_44()), + D::U1 => part(PartRole::Rom, mask_rom_tsop_ii_44_5v()), // QFP-32 MBC5 D::U2 => part(PartRole::Mapper, mapper::mbc5_qfp32()), // SOP-28 RAM - D::U3 => part(PartRole::Ram, sram_sop_28()), + D::U3 => part(PartRole::Ram, sram_sop_28_5v()), // SOP-8 MM1134 D::U4 => part(PartRole::SupervisorReset, supervisor_reset()), // TSOP-II-44 ROM - D::U5 => part(PartRole::Rom, mask_rom_tsop_ii_44()), + D::U5 => part(PartRole::Rom, mask_rom_tsop_ii_44_5v()), // SSOP-8 D::U6 => part(PartRole::LineDecoder, line_decoder()), _ => None, @@ -395,7 +392,7 @@ impl BoardConfig { // QFP-32 MBC5 D::U2 => part(PartRole::Mapper, mapper::mbc5_qfp32()), // SOP-32 RAM - D::U3 => part(PartRole::Ram, sram_sop_32()), + D::U3 => part(PartRole::Ram, sram_sop_32_5v()), // SOP-8 MM1134A D::U4 => part(PartRole::SupervisorReset, supervisor_reset()), _ => None, @@ -415,7 +412,7 @@ impl BoardConfig { // QFP-56 MBC7 D::U1 => part(PartRole::Mapper, mapper::mbc7_qfp56()), // TSOP-II-44 ROM - D::U2 => part(PartRole::Rom, mask_rom_tsop_ii_44()), + D::U2 => part(PartRole::Rom, mask_rom_tsop_ii_44_5v()), // TSSOP-8 EEPROM D::U3 => part(PartRole::Eeprom, eeprom()), // QC-14 accelerometer @@ -449,7 +446,7 @@ impl BoardConfig { // SOP-24 MBC1 D::U2 => part(PartRole::Mapper, mapper::mbc1_sop24()), // SOP-28 RAM - D::U3 => part(PartRole::Ram, sram_sop_28()), + D::U3 => part(PartRole::Ram, sram_sop_28_5v()), // SOP-8 26A D::U4 => part(PartRole::SupervisorReset, supervisor_reset()), _ => None, @@ -457,11 +454,11 @@ impl BoardConfig { } BoardConfig::DmgDgcu => match designator { // TSOP-II-44 ROM - D::U1 => part(PartRole::Rom, mask_rom_tsop_ii_44()), + D::U1 => part(PartRole::Rom, mask_rom_tsop_ii_44_5v()), // SOP-24 MBC1 D::U2 => part(PartRole::Mapper, mapper::mbc1_sop24()), // SOP-28 RAM - D::U3 => part(PartRole::Ram, sram_sop_28()), + D::U3 => part(PartRole::Ram, sram_sop_28_5v()), // SOP-8 MM1134A D::U4 => part(PartRole::SupervisorReset, supervisor_reset()), _ => None, @@ -481,7 +478,7 @@ impl BoardConfig { // QFP-32 MBC3 D::U2 => part(PartRole::Mapper, mapper::mbc3_qfp32()), // SOP-28 RAM - D::U3 => part(PartRole::Ram, sram_sop_28()), + D::U3 => part(PartRole::Ram, sram_sop_28_5v()), // SOP-8 26A / MM1134 D::U4 => part(PartRole::SupervisorReset, supervisor_reset()), D::X1 => part(PartRole::Crystal, crystal_32kihz()), @@ -493,7 +490,7 @@ impl BoardConfig { // QFP-32 MBC3 D::U2 => part(PartRole::Mapper, mapper::mbc3_qfp32()), // SOP-28 RAM - D::U3 => part(PartRole::Ram, sram_sop_28()), + D::U3 => part(PartRole::Ram, sram_sop_28_5v()), // SOP-8 MM1134 D::U4 => part(PartRole::SupervisorReset, supervisor_reset()), D::X1 => part(PartRole::Crystal, crystal_32kihz()), @@ -501,11 +498,11 @@ impl BoardConfig { }, BoardConfig::DmgKgdu => match designator { // TSOP-II-44 ROM - D::U1 => part(PartRole::Rom, mask_rom_tsop_ii_44()), + D::U1 => part(PartRole::Rom, mask_rom_tsop_ii_44_5v()), // QFP-32 MBC3 D::U2 => part(PartRole::Mapper, mapper::mbc3_qfp32()), // SOP-28 RAM - D::U3 => part(PartRole::Ram, sram_sop_28()), + D::U3 => part(PartRole::Ram, sram_sop_28_5v()), // SOP-8 MM1134 D::U4 => part(PartRole::SupervisorReset, supervisor_reset()), D::X1 => part(PartRole::Crystal, crystal_32kihz()), @@ -517,7 +514,7 @@ impl BoardConfig { // QFP-32 MBC3 D::U2 => part(PartRole::Mapper, mapper::mbc3_qfp32()), // SOP-28 RAM - D::U3 => part(PartRole::Ram, sram_sop_28()), + D::U3 => part(PartRole::Ram, sram_sop_28_5v()), // SOP-8 MM1134 D::U4 => part(PartRole::SupervisorReset, supervisor_reset()), _ => None, @@ -528,18 +525,18 @@ impl BoardConfig { // QFP-32 MMM01 D::U2 => part(PartRole::Mapper, mapper::mmm01_qfp32()), // SOP-28 RAM - D::U3 => part(PartRole::Ram, sram_sop_28()), + D::U3 => part(PartRole::Ram, sram_sop_28_5v()), // SOP-8 26A D::U4 => part(PartRole::SupervisorReset, supervisor_reset()), _ => None, }, BoardConfig::DmgMheu => match designator { // TSOP-II-44 ROM - D::U1 => part(PartRole::Rom, mask_rom_tsop_ii_44()), + D::U1 => part(PartRole::Rom, mask_rom_tsop_ii_44_5v()), // QFP-32 MBC30 D::U2 => part(PartRole::Mapper, mapper::mbc30_qfp32()), // SOP-32 RAM - D::U3 => part(PartRole::Ram, sram_sop_32()), + D::U3 => part(PartRole::Ram, sram_sop_32_5v()), // SOP-8 MM1134 D::U4 => part(PartRole::SupervisorReset, supervisor_reset()), D::X1 => part(PartRole::Crystal, crystal_32kihz()), @@ -551,7 +548,7 @@ impl BoardConfig { // QFP-32 HuC-1 D::U2 => part(PartRole::Mapper, mapper::huc1_qfp32()), // SOP-28 RAM - D::U3 => part(PartRole::Ram, sram_sop_28()), + D::U3 => part(PartRole::Ram, sram_sop_28_5v()), // SOP-8 26A D::U4 => part(PartRole::SupervisorReset, supervisor_reset()), D::X1 => part(PartRole::Crystal, crystal_32kihz()), @@ -563,7 +560,7 @@ impl BoardConfig { // QFP-32 HuC-1 D::U2 => part(PartRole::Mapper, mapper::huc1_qfp32()), // SOP-28 RAM - D::U3 => part(PartRole::Ram, sram_sop_28()), + D::U3 => part(PartRole::Ram, sram_sop_28_5v()), // SOP-8 1134A D::U4 => part(PartRole::SupervisorReset, supervisor_reset()), D::X1 => part(PartRole::Crystal, crystal_32kihz()), @@ -599,7 +596,7 @@ impl BoardConfig { }, BoardConfig::DmgUgdu => match designator { // TSOP-II-44 ROM - D::U1 => part(PartRole::Rom, mask_rom_tsop_ii_44()), + D::U1 => part(PartRole::Rom, mask_rom_tsop_ii_44_5v()), // QFP-48 HuC-3 D::U2 => part(PartRole::Mapper, mapper::huc3_qfp48()), // TSOP-I-28 RAM @@ -617,29 +614,29 @@ impl BoardConfig { // QFP-32 MBC5 D::U2 => part(PartRole::Mapper, mapper::mbc5_qfp32()), // SOP-28 RAM - D::U3 => part(PartRole::Ram, sram_sop_28()), + D::U3 => part(PartRole::Ram, sram_sop_28_5v()), // SOP-8 MM1134A D::U4 => part(PartRole::SupervisorReset, supervisor_reset()), _ => None, }, BoardConfig::DmgZ03 => match designator { // TSOP-II-44 ROM - D::U1 => part(PartRole::Rom, mask_rom_tsop_ii_44()), + D::U1 => part(PartRole::Rom, mask_rom_tsop_ii_44_5v()), // QFP-32 MBC5 D::U2 => part(PartRole::Mapper, mapper::mbc5_qfp32()), // SOP-28 RAM - D::U3 => part(PartRole::Ram, sram_sop_28()), + D::U3 => part(PartRole::Ram, sram_sop_28_5v()), // SOP-8 MM1134A D::U4 => part(PartRole::SupervisorReset, supervisor_reset()), _ => None, }, BoardConfig::DmgZ04 => match designator { // TSOP-II-44 ROM - D::U1 => part(PartRole::Rom, mask_rom_tsop_ii_44()), + D::U1 => part(PartRole::Rom, mask_rom_tsop_ii_44_5v()), // QFP-32 MBC5 D::U2 => part(PartRole::Mapper, mapper::mbc5_qfp32()), // SOP-28 RAM - D::U3 => part(PartRole::Ram, sram_sop_28()), + D::U3 => part(PartRole::Ram, sram_sop_28_5v()), // SOP-8 MM1134A D::U4 => part(PartRole::SupervisorReset, supervisor_reset()), // MOT1 => motor diff --git a/backend/src/parser.rs b/backend/src/parser.rs index 36fadf492..4f7c544ab 100644 --- a/backend/src/parser.rs +++ b/backend/src/parser.rs @@ -8,62 +8,39 @@ use regex::{Captures, Regex, RegexBuilder}; use std::{any::Any, fmt, str::FromStr}; use crate::{ - macros::single_parser, + macros::{multi_parser, single_parser}, time::{Month, Week}, }; pub use self::{ accelerometer::Accelerometer, - agb_amp::AgbAmp, - agb_pmic::AgbPmic, - agb_reg::AgbReg, ags_charge_ctrl::AgsChargeController, - ags_pmic_old::AgsPmicOld, - cgb_reg::CgbReg, cgb_soc::CgbSoc, cgb_stamp::CgbStamp, cic::Cic, coil::Coil, - dmg_amp::DmgAmp, - dmg_reg::DmgReg, dmg_stamp::DmgStamp, eeprom::Eeprom, - flash::Flash, - fram::Fram, gbs_dol::GbsDol, - gbs_reg::GbsReg, gen1_soc::{Gen1Soc, Gen1SocKind}, gen2_soc::{Gen2Soc, Gen2SocKind}, - hex_inverter::HexInverter, icd2::Icd2, lcd_chip::LcdChip, lcd_screen::LcdScreen, - line_decoder::LineDecoder, mapper::{Huc1Version, Mapper, MapperType, Mbc1Version, Mbc2Version, Mbc3Version}, mask_rom::MaskRom, - mgb_amp::MgbAmp, - mgl_transformer::Transformer, - oxy_pmic::OxyPmic, - oxy_u4::OxyU4, - oxy_u5::OxyU5, - rtc::Rtc, sgb_rom::SgbRom, - sram::StaticRam, - supervisor_reset::SupervisorReset, tama::{Tama, TamaType}, }; pub mod accelerometer; -pub mod agb_amp; -pub mod agb_pmic; -pub mod agb_reg; pub mod agb_soc_bga; pub mod agb_soc_qfp_128; pub mod agb_soc_qfp_156; pub mod ags_charge_ctrl; -pub mod ags_pmic_new; -pub mod ags_pmic_old; -pub mod cgb_reg; +pub mod amic; +pub mod atmel; +pub mod bsi; pub mod cgb_soc; pub mod cgb_stamp; pub mod cic; @@ -73,51 +50,57 @@ pub mod crystal_32kihz; pub mod crystal_32mihz; pub mod crystal_4mihz; pub mod crystal_8mihz; -pub mod dmg_amp; -pub mod dmg_reg; pub mod dmg_stamp; pub mod eeprom; -pub mod flash; -pub mod fram; +pub mod fujitsu; pub mod gbs_dol; -pub mod gbs_reg; pub mod gen1_soc; pub mod gen2_soc; -pub mod hex_inverter; +pub mod hynix; +pub mod hyundai; pub mod icd2; pub mod lcd_chip; pub mod lcd_screen; -pub mod line_decoder; +pub mod lgs; +pub mod macronix; pub mod mapper; pub mod mask_rom; -pub mod mgb_amp; -pub mod mgl_transformer; -pub mod oxy_pmic; +pub mod mitsubishi; +pub mod mitsumi; +pub mod nec; pub mod oxy_u4; pub mod oxy_u5; -pub mod rtc; +pub mod rohm; +pub mod sanyo; +pub mod seiko; pub mod sgb_rom; +pub mod sharp; pub mod sram; -pub mod supervisor_reset; +pub mod sst; +pub mod st_micro; pub mod tama; +pub mod ti; +pub mod toshiba; +pub mod victronix; +pub mod winbond; pub trait ParsedData: fmt::Debug + Any {} #[derive(Copy, Clone, Debug, PartialEq, Eq)] -pub enum ChipDateCode { +pub enum PartDateCode { Year { year: Year }, YearMonth { year: Year, month: Month }, YearWeek { year: Year, week: Week }, } #[derive(Clone, Debug, Eq, PartialEq)] -pub struct GenericChip { +pub struct GenericPart { pub kind: String, pub manufacturer: Option, - pub date_code: Option, + pub date_code: Option, } -impl ParsedData for GenericChip {} +impl ParsedData for GenericPart {} #[derive(Clone, Debug, Eq, PartialEq)] pub struct ChipYearWeek { @@ -291,131 +274,36 @@ pub fn year1(text: &str) -> Result { } } -mod seiko { - use nom::{ - character::streaming::{anychar, satisfy}, - combinator::map_opt, - error::ParseError, - multi::count, - IResult, Parser, - }; - - use super::Year; - - pub fn year1<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&'a str, Year, E> { - map_opt(anychar, |ch| match ch { - '0' => Some(Year::Partial(0)), - '1' | 'A' => Some(Year::Partial(1)), - '2' | 'B' => Some(Year::Partial(2)), - '3' | 'C' => Some(Year::Partial(3)), - '4' | 'D' => Some(Year::Partial(4)), - '5' | 'E' => Some(Year::Partial(5)), - '6' | 'F' => Some(Year::Partial(6)), - '7' | 'G' => Some(Year::Partial(7)), - '8' | 'H' => Some(Year::Partial(8)), - '9' | 'J' => Some(Year::Partial(9)), - _ => None, - }) - .parse(input) - } - - pub fn lot_code<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&'a str, (), E> { - count(satisfy(|c| c.is_ascii_digit()), 4) - .map(|_| ()) - .parse(input) - } -} - -mod macronix { +mod for_nom { use nom::{ - character::streaming::satisfy, - combinator::{opt, recognize}, + bytes::streaming::{tag, take}, + character::streaming::{anychar, char, satisfy}, + combinator::{map_opt, recognize}, error::ParseError, + multi::fold_many_m_n, sequence::tuple, - IResult, Parser as _, - }; - - use super::{ - for_nom::{self, digits, uppers}, - ChipDateCode, + IResult, Parser, }; - pub fn assembly_vendor_code<'a, E: ParseError<&'a str>>( - input: &'a str, - ) -> IResult<&'a str, char, E> { - satisfy(|c| match c { - 'a' => true, // ChipMOS - 'B' => true, // OSE / Orient Semiconductor Electronics - 'E' => true, // ??? - 'K' => true, // ASEKS - 'J' => true, // ASEJ - 'L' => true, // LINGSEN - 'M' => true, // ??? - 'N' => true, // ??? - 'S' => true, // SPIL - 'T' => true, // STS - 'X' => true, // ASECL - _ => false, - }) - .parse(input) - } - - pub fn date_code<'a, E: ParseError<&'a str>>( - input: &'a str, - ) -> IResult<&'a str, ChipDateCode, E> { - for_nom::year2_week2(input) - } + use super::{PartDateCode, Year}; + use crate::time::{Month, Week}; - pub fn lot_code_new<'a, E: ParseError<&'a str>>( - input: &'a str, - ) -> IResult<&'a str, &'a str, E> { - // [0-9][A-Z][0-9]{4} + [0-9]{2}[A-Z][0-9] + pub fn dmg_rom_code<'a, E: ParseError<&'a str>>() -> impl Parser<&'a str, &'a str, E> { recognize(tuple(( - tuple((digits(1), uppers(1), digits(4))), - opt(nom::bytes::complete::take(4_usize).and_then(tuple(( - digits(2), - uppers(1), - digits(1), - )))), + tag("DMG-"), + satisfy_m_n(3, 4, |c| c.is_ascii_digit() || c.is_ascii_uppercase()), + char('-'), + digits(1), ))) - .parse(input) - } - - pub fn lot_code_old<'a, E: ParseError<&'a str>>( - input: &'a str, - ) -> IResult<&'a str, &'a str, E> { - digits(5).parse(input) } -} -mod toshiba { - #[derive(Copy, Clone, Debug, PartialEq, Eq)] - pub enum Package { - SOP, + pub fn cgb_rom_code<'a, E: ParseError<&'a str>>() -> impl Parser<&'a str, &'a str, E> { + recognize(tuple((tag("CGB-"), alnum_uppers(4), char('-'), digits(1)))) } - impl Package { - pub const fn code_char(&self) -> char { - match self { - Package::SOP => 'M', - } - } + pub fn agb_rom_code<'a, E: ParseError<&'a str>>() -> impl Parser<&'a str, &'a str, E> { + recognize(tuple((tag("AGB-"), alnum_uppers(4), char('-'), digits(1)))) } -} - -mod for_nom { - use nom::{ - bytes::streaming::take, - character::streaming::satisfy, - combinator::{map_opt, recognize}, - error::ParseError, - multi::fold_many_m_n, - sequence::tuple, - IResult, Parser, - }; - - use super::{ChipDateCode, Year}; - use crate::time::{Month, Week}; pub fn satisfy_m_n<'a, E: ParseError<&'a str>>( min: usize, @@ -437,6 +325,10 @@ mod for_nom { satisfy_m_n(count, count, |c| c.is_ascii_uppercase()) } + pub fn alphas<'a, E: ParseError<&'a str>>(count: usize) -> impl Parser<&'a str, &'a str, E> { + satisfy_m_n(count, count, |c| c.is_ascii_alphabetic()) + } + pub fn digits<'a, E: ParseError<&'a str>>(count: usize) -> impl Parser<&'a str, &'a str, E> { satisfy_m_n(count, count, |c| c.is_ascii_digit()) } @@ -462,29 +354,75 @@ mod for_nom { .parse(input) } + pub fn year1_week2<'a, E: ParseError<&'a str>>( + input: &'a str, + ) -> IResult<&'a str, PartDateCode, E> { + tuple((year1, week2)) + .map(|(year, week)| PartDateCode::YearWeek { year, week }) + .parse(input) + } + pub fn year2_week2<'a, E: ParseError<&'a str>>( input: &'a str, - ) -> IResult<&'a str, ChipDateCode, E> { + ) -> IResult<&'a str, PartDateCode, E> { tuple((year2, week2)) - .map(|(year, week)| ChipDateCode::YearWeek { year, week }) + .map(|(year, week)| PartDateCode::YearWeek { year, week }) .parse(input) } - pub fn month1_alpha<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&'a str, Month, E> { + pub fn month1_123abc<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&'a str, Month, E> { map_opt(take(1_usize), |text| match text { - "A" => Some(Month::January), - "B" => Some(Month::February), - "C" => Some(Month::March), - "D" => Some(Month::April), - "E" => Some(Month::May), - "F" => Some(Month::June), - "G" => Some(Month::July), - "H" => Some(Month::August), + "1" => Some(Month::January), + "2" => Some(Month::February), + "3" => Some(Month::March), + "4" => Some(Month::April), + "5" => Some(Month::May), + "6" => Some(Month::June), + "7" => Some(Month::July), + "8" => Some(Month::August), + "9" => Some(Month::September), + "A" => Some(Month::October), + "B" => Some(Month::November), + "C" => Some(Month::December), + _ => None, + }) + .parse(input) + } + + pub fn month1_123xyz<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&'a str, Month, E> { + map_opt(anychar, |ch| match ch { + '1' => Some(Month::January), + '2' => Some(Month::February), + '3' => Some(Month::March), + '4' => Some(Month::April), + '5' => Some(Month::May), + '6' => Some(Month::June), + '7' => Some(Month::July), + '8' => Some(Month::August), + '9' => Some(Month::September), + 'X' => Some(Month::October), + 'Y' => Some(Month::November), + 'Z' => Some(Month::December), + _ => None, + }) + .parse(input) + } + + pub fn month1_abc<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&'a str, Month, E> { + map_opt(anychar, |text| match text { + 'A' => Some(Month::January), + 'B' => Some(Month::February), + 'C' => Some(Month::March), + 'D' => Some(Month::April), + 'E' => Some(Month::May), + 'F' => Some(Month::June), + 'G' => Some(Month::July), + 'H' => Some(Month::August), // I is intentionally skipped - "J" => Some(Month::September), - "K" => Some(Month::October), - "L" => Some(Month::November), - "M" => Some(Month::December), + 'J' => Some(Month::September), + 'K' => Some(Month::October), + 'L' => Some(Month::November), + 'M' => Some(Month::December), _ => None, }) .parse(input) @@ -579,7 +517,7 @@ impl LabelParser for NomParser { fn parse(&self, label: &str) -> Result { match all_consuming(self.f).parse(label) { Ok((_, chip)) => Ok(chip), - Err(err) => Err(format!("{err:?}")), + Err(err) => Err(format!("{label}:{err:?}")), } } } @@ -618,3 +556,102 @@ impl ParsedData for UnknownChip {} pub fn unknown_chip() -> &'static impl LabelParser { single_parser!(UnknownChip, r#"^.*$"#, move |_| Ok(UnknownChip)) } + +pub fn mgb_amp() -> &'static impl LabelParser { + multi_parser!(GenericPart, &sharp::SHARP_IR3R53, &sharp::SHARP_IR3R56) +} + +pub fn agb_amp() -> &'static impl LabelParser { + multi_parser!(GenericPart, &sharp::SHARP_IR3R60, &rohm::ROHM_BH7835AFS,) +} + +pub fn agb_reg() -> &'static impl LabelParser { + &sharp::SHARP_IR3E09 +} + +pub fn cgb_reg() -> &'static impl LabelParser { + &sharp::SHARP_IR3E06 +} + +pub fn dmg_amp() -> &'static impl LabelParser { + &sharp::SHARP_IR3R40 +} + +pub fn dmg_reg() -> &'static impl LabelParser { + &sharp::SHARP_IR3E02 +} + +pub fn rtc_sop_8() -> &'static impl LabelParser { + multi_parser!(GenericPart, &seiko::SEIKO_S3511A, &seiko::SEIKO_S3516AE) +} + +pub fn rtc_sop_20() -> &'static impl LabelParser { + multi_parser!(GenericPart, &toshiba::TOSHIBA_TC8521AM) +} + +pub fn line_decoder() -> &'static impl LabelParser { + &toshiba::TOSHIBA_TC7W139F +} + +pub fn hex_inverter() -> &'static impl LabelParser { + &toshiba::TOSHIBA_TC74LVX04FT +} + +pub fn flash_tsop_i_32_3v3() -> &'static impl LabelParser { + multi_parser!( + GenericPart, + ¯onix::MACRONIX_MX29L010, + &sanyo::SANYO_LE26FV10, + &atmel::ATMEL_AT29LV512, + &sst::SST_SST39VF512, + ) +} + +pub fn flash_tsop_i_40_5v() -> &'static impl LabelParser { + multi_parser!(GenericPart, ¯onix::MACRONIX_MX29F008) +} + +pub fn supervisor_reset() -> &'static impl LabelParser { + multi_parser!( + GenericPart, + &mitsumi::MITSUMI_MM1026A, + &mitsumi::MITSUMI_MM1134A, + &rohm::ROHM_BA6129, + &rohm::ROHM_BA6735, + &mitsubishi::MITSUBISHI_M62021P, + &ti::TI_SN74LV2416, + ) +} + +pub fn gbs_reg() -> &'static impl LabelParser { + &mitsumi::MITSUMI_MM1592F +} + +pub fn oxy_pmic() -> &'static impl LabelParser { + &mitsumi::MITSUMI_PM +} + +pub fn ags_pmic_new() -> &'static impl LabelParser { + &mitsumi::MITSUMI_PM +} + +pub fn mgl_transformer() -> &'static impl LabelParser { + &mitsumi::MITSUMI_MGL_TRANSFORMER +} + +pub fn agb_pmic() -> &'static impl LabelParser { + multi_parser!( + GenericPart, + &mitsumi::MITSUMI_MM1514X, + &seiko::SEIKO_S6960E, + &rohm::ROHM_9750 + ) +} + +pub fn ags_pmic_old() -> &'static impl LabelParser { + multi_parser!(GenericPart, &seiko::SEIKO_S6403, &rohm::ROHM_9753) +} + +pub fn fram_sop_28_3v3() -> &'static impl LabelParser { + multi_parser!(GenericPart, &fujitsu::FUJITSU_MB85R256,) +} diff --git a/backend/src/parser/accelerometer.rs b/backend/src/parser/accelerometer.rs index 3b44e316b..2750ad6d5 100644 --- a/backend/src/parser/accelerometer.rs +++ b/backend/src/parser/accelerometer.rs @@ -2,49 +2,63 @@ // // SPDX-License-Identifier: MIT -use super::{week2, year2, ChipYearWeek, LabelParser, Manufacturer}; -use crate::macros::{multi_parser, single_parser}; +use nom::{bytes::streaming::tag, character::streaming::char, sequence::tuple, Parser as _}; -pub type Accelerometer = ChipYearWeek; +use super::{ + for_nom::{digits, uppers, year2_week2}, + GenericPart, LabelParser, Manufacturer, NomParser, +}; +use crate::macros::multi_parser; + +pub type Accelerometer = GenericPart; /// ``` /// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::accelerometer::accelerometer().parse("2738109451 0028 ADXL202JQC").is_ok()); +/// assert!(parser::accelerometer::ANALOG_ADXL202JQC.parse("2738109451 0028 ADXL202JQC").is_ok()); /// ``` -pub fn analog_adxl202jqc() -> &'static impl LabelParser { - single_parser!( - ChipYearWeek, - r#"^[0-9]{10}\ ([0-9]{2})([0-9]{2})\ ADXL202JQC$"#, - move |c| { - Ok(ChipYearWeek { - kind: "ADXL202JQC".to_owned(), - manufacturer: Some(Manufacturer::Analog), - year: Some(year2(&c[1])?), - week: Some(week2(&c[2])?), - }) - } - ) -} +pub static ANALOG_ADXL202JQC: NomParser = NomParser { + name: "Analog ADXL202JQC", + f: |input| { + tuple(( + digits(10), + char(' '), + year2_week2, + char(' '), + tag("ADXL202JQC"), + )) + .map(|(_, _, date_code, _, kind)| Accelerometer { + kind: String::from(kind), + manufacturer: Some(Manufacturer::Analog), + date_code: Some(date_code), + }) + .parse(input) + }, +}; /// ``` /// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::accelerometer::accelerometer().parse("06245 202JE 0501A").is_ok()); +/// assert!(parser::accelerometer::ANALOG_ADXL202JE.parse("06245 202JE 0501A").is_ok()); /// ``` -pub fn analog_adxl202je() -> &'static impl LabelParser { - single_parser!( - ChipYearWeek, - r#"^[0-9]{5}\ 202JE\ [0-9]{4}[A-Z]$"#, - move |_| { - Ok(ChipYearWeek { - kind: "ADXL202JE".to_owned(), - manufacturer: Some(Manufacturer::Analog), - year: None, - week: None, - }) - } - ) -} +pub static ANALOG_ADXL202JE: NomParser = NomParser { + name: "Analog ADXL202JE", + f: |input| { + tuple(( + digits(5), + char(' '), + tag("202JE"), + char(' '), + digits(4), + uppers(1), + )) + .map(|(_, _, kind, _, _, _)| Accelerometer { + kind: format!("ADXL{kind}"), + manufacturer: Some(Manufacturer::Analog), + date_code: None, + }) + .parse(input) + }, +}; pub fn accelerometer() -> &'static impl LabelParser { - multi_parser!(Accelerometer, analog_adxl202jqc(), analog_adxl202je(),) + multi_parser!(Accelerometer, &ANALOG_ADXL202JQC, &ANALOG_ADXL202JE) } diff --git a/backend/src/parser/agb_amp.rs b/backend/src/parser/agb_amp.rs deleted file mode 100644 index bd9da8bbe..000000000 --- a/backend/src/parser/agb_amp.rs +++ /dev/null @@ -1,50 +0,0 @@ -// SPDX-FileCopyrightText: 2017-2023 Joonas Javanainen -// -// SPDX-License-Identifier: MIT - -use super::{week2, year1, year2, ChipYearWeek, LabelParser, Manufacturer}; -use crate::macros::{multi_parser, single_parser}; - -pub type AgbAmp = ChipYearWeek; - -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::agb_amp::sharp_ir3r60n().parse("AMP AGB IR3R60N 0103 a").is_ok()); -/// ``` -pub fn sharp_ir3r60n() -> &'static impl LabelParser { - single_parser!( - AgbAmp, - r#"^AMP\ AGB\ IR3R60N\ ([A0-9]{2})([0-9]{2})\ [A-Za-z]$"#, - move |c| { - Ok(AgbAmp { - kind: "IR3R60N".to_owned(), - manufacturer: Some(Manufacturer::Sharp), - year: Some(year2(&c[1])?), - week: Some(week2(&c[2])?), - }) - }, - ) -} - -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::agb_amp::rohm_bh7835afs().parse("BH7835AFS 337 T22").is_ok()); -/// ``` -pub fn rohm_bh7835afs() -> &'static impl LabelParser { - single_parser!( - AgbAmp, - r#"^BH7835AFS\ ([0-9])([0-9]{2})\ [[:alnum:]][0-9]{2}$"#, - move |c| { - Ok(AgbAmp { - kind: "BH7835AFS".to_owned(), - manufacturer: Some(Manufacturer::Rohm), - year: Some(year1(&c[1])?), - week: Some(week2(&c[2])?), - }) - }, - ) -} - -pub fn agb_amp() -> &'static impl LabelParser { - multi_parser!(AgbAmp, sharp_ir3r60n(), rohm_bh7835afs(),) -} diff --git a/backend/src/parser/agb_pmic.rs b/backend/src/parser/agb_pmic.rs deleted file mode 100644 index 594f90a5c..000000000 --- a/backend/src/parser/agb_pmic.rs +++ /dev/null @@ -1,88 +0,0 @@ -// SPDX-FileCopyrightText: 2017-2023 Joonas Javanainen -// -// SPDX-License-Identifier: MIT - -use super::{week2, year1, ChipYearWeek, LabelParser, Manufacturer}; -use crate::macros::{multi_parser, single_parser}; - -pub type AgbPmic = ChipYearWeek; - -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::agb_pmic::mitsumi_mm1514x().parse("105 514X").is_ok()); -/// ``` -pub fn mitsumi_mm1514x() -> &'static impl LabelParser { - single_parser!(AgbPmic, r#"^([1-9])([0-5][0-9])\ 514X$"#, move |c| { - Ok(AgbPmic { - kind: "MM1514X".to_owned(), - manufacturer: Some(Manufacturer::Mitsumi), - year: Some(year1(&c[1])?), - week: Some(week2(&c[2])?), - }) - }) -} - -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::agb_pmic::mitsumi_mm1514x_2().parse("081 514X").is_ok()); -/// ``` -pub fn mitsumi_mm1514x_2() -> &'static impl LabelParser { - single_parser!(AgbPmic, r#"^(0)[0-9]{2}\ 514X$"#, move |c| { - Ok(AgbPmic { - kind: "MM1514X".to_owned(), - manufacturer: Some(Manufacturer::Mitsumi), - year: Some(year1(&c[1])?), - week: None, - }) - }) -} - -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::agb_pmic::unknown().parse("S6960 E-U2Z C700").is_ok()); -/// assert!(parser::agb_pmic::unknown().parse("S6960 E-U2X C410").is_ok()); -/// ``` -pub fn unknown() -> &'static impl LabelParser { - single_parser!( - AgbPmic, - r#"^S6960\ E-U([0-9])[A-Z]\ C[0-9]{3}$"#, - move |c| { - Ok(AgbPmic { - kind: "S6960".to_owned(), - manufacturer: None, - year: Some(year1(&c[1])?), - week: None, - }) - } - ) -} - -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::agb_pmic::unknown2().parse("9750A 1581").is_ok()); -/// assert!(parser::agb_pmic::unknown2().parse("9750B 2A69").is_ok()); -/// ``` -pub fn unknown2() -> &'static impl LabelParser { - single_parser!( - AgbPmic, - r#"^(9750[AB])\ ([0-9])[[:alnum:]][0-9]{2}$"#, - move |c| { - Ok(AgbPmic { - kind: c[1].to_owned(), - manufacturer: None, - year: Some(year1(&c[2])?), - week: None, - }) - } - ) -} - -pub fn agb_pmic() -> &'static impl LabelParser { - multi_parser!( - AgbPmic, - mitsumi_mm1514x(), - mitsumi_mm1514x_2(), - unknown(), - unknown2() - ) -} diff --git a/backend/src/parser/agb_reg.rs b/backend/src/parser/agb_reg.rs deleted file mode 100644 index 03be972c1..000000000 --- a/backend/src/parser/agb_reg.rs +++ /dev/null @@ -1,31 +0,0 @@ -// SPDX-FileCopyrightText: 2017-2023 Joonas Javanainen -// -// SPDX-License-Identifier: MIT - -use super::{week2, year2, ChipYearWeek, LabelParser}; -use crate::{macros::single_parser, parser::Manufacturer}; - -pub type AgbReg = ChipYearWeek; - -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::agb_reg::sharp_ir3e09n().parse("AGB-REG IR3E09N 0104 C").is_ok()); -/// ``` -pub fn sharp_ir3e09n() -> &'static impl LabelParser { - single_parser!( - AgbReg, - r#"^AGB-REG\ IR3E09N\ ([A0-9]{2})([0-9]{2})\ [a-zA-Z]{1,2}$"#, - move |c| { - Ok(AgbReg { - kind: "IR3E09N".to_owned(), - manufacturer: Some(Manufacturer::Sharp), - year: Some(year2(&c[1])?), - week: Some(week2(&c[2])?), - }) - }, - ) -} - -pub fn agb_reg() -> &'static impl LabelParser { - sharp_ir3e09n() -} diff --git a/backend/src/parser/ags_charge_ctrl.rs b/backend/src/parser/ags_charge_ctrl.rs index 9b2ec0daf..0278ec871 100644 --- a/backend/src/parser/ags_charge_ctrl.rs +++ b/backend/src/parser/ags_charge_ctrl.rs @@ -2,29 +2,13 @@ // // SPDX-License-Identifier: MIT -use super::{week2, year1, ChipYearWeek, LabelParser, Manufacturer}; -use crate::macros::{multi_parser, single_parser}; +use super::{week2, year1, GenericPart, LabelParser}; +use crate::{ + macros::{multi_parser, single_parser}, + parser::{mitsumi, PartDateCode}, +}; -pub type AgsChargeController = ChipYearWeek; - -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::ags_charge_ctrl::mitsumi_mm1581a().parse("422 1581A").is_ok()); -/// ``` -pub fn mitsumi_mm1581a() -> &'static impl LabelParser { - single_parser!( - AgsChargeController, - r#"^([0-9])([0-9]{2})\ 1581A$"#, - move |c| { - Ok(AgsChargeController { - kind: "MM1581A".to_owned(), - manufacturer: Some(Manufacturer::Mitsumi), - year: Some(year1(&c[1])?), - week: Some(week2(&c[2])?), - }) - } - ) -} +pub type AgsChargeController = GenericPart; /// ``` /// use gbhwdb_backend::parser::{self, LabelParser}; @@ -38,13 +22,15 @@ pub fn unknown() -> &'static impl LabelParser { Ok(AgsChargeController { kind: "2253B".to_owned(), manufacturer: None, - year: Some(year1(&c[1])?), - week: Some(week2(&c[2])?), + date_code: Some(PartDateCode::YearWeek { + year: year1(&c[1])?, + week: week2(&c[2])?, + }), }) } ) } pub fn ags_charge_ctrl() -> &'static impl LabelParser { - multi_parser!(AgsChargeController, mitsumi_mm1581a(), unknown()) + multi_parser!(AgsChargeController, &mitsumi::MITSUMI_MM1581A, unknown()) } diff --git a/backend/src/parser/ags_pmic_new.rs b/backend/src/parser/ags_pmic_new.rs deleted file mode 100644 index c5ea8a0bb..000000000 --- a/backend/src/parser/ags_pmic_new.rs +++ /dev/null @@ -1,32 +0,0 @@ -// SPDX-FileCopyrightText: 2017-2023 Joonas Javanainen -// -// SPDX-License-Identifier: MIT - -use super::{week2, year1, AgbAmp, ChipYearWeek, LabelParser, Manufacturer}; -use crate::macros::single_parser; - -pub type AgsPmicNew = ChipYearWeek; - -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::ags_pmic_new::mitsumi_pm().parse("MITSUMI JAPAN 602E PM B3").is_ok()); -/// ``` -pub fn mitsumi_pm() -> &'static impl LabelParser { - // FIXME: Not really an amplifier - single_parser!( - AgbAmp, - r#"^MITSUMI\ JAPAN\ ([0-9])([0-9]{2})[A-Z]\ (PM\ B[0-9])$"#, - move |c| { - Ok(AgbAmp { - kind: c[3].to_owned(), - manufacturer: Some(Manufacturer::Mitsumi), - year: Some(year1(&c[1])?), - week: Some(week2(&c[2])?), - }) - }, - ) -} - -pub fn ags_pmic_new() -> &'static impl LabelParser { - mitsumi_pm() -} diff --git a/backend/src/parser/ags_pmic_old.rs b/backend/src/parser/ags_pmic_old.rs deleted file mode 100644 index bc36e200b..000000000 --- a/backend/src/parser/ags_pmic_old.rs +++ /dev/null @@ -1,50 +0,0 @@ -// SPDX-FileCopyrightText: 2017-2023 Joonas Javanainen -// -// SPDX-License-Identifier: MIT - -use super::{year1, ChipYearWeek, LabelParser}; -use crate::macros::{multi_parser, single_parser}; - -pub type AgsPmicOld = ChipYearWeek; - -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::ags_pmic_old::unknown().parse("S6403 CU4E0 9723").is_ok()); -/// ``` -pub fn unknown() -> &'static impl LabelParser { - single_parser!( - AgsPmicOld, - r#"^S6403\ [[:alnum:]]{5}\ [0-9]{4}$"#, - move |_| { - Ok(AgsPmicOld { - kind: "S6403".to_owned(), - manufacturer: None, - year: None, - week: None, - }) - } - ) -} - -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::ags_pmic_old::unknown2().parse("9753 4862").is_ok()); -/// ``` -pub fn unknown2() -> &'static impl LabelParser { - single_parser!( - AgsPmicOld, - r#"^(9753)\ ([0-9])[[:alnum:]][0-9]{2}$"#, - move |c| { - Ok(AgsPmicOld { - kind: c[1].to_owned(), - manufacturer: None, - year: Some(year1(&c[2])?), - week: None, - }) - } - ) -} - -pub fn ags_pmic_old() -> &'static impl LabelParser { - multi_parser!(AgsPmicOld, unknown(), unknown2()) -} diff --git a/backend/src/parser/amic.rs b/backend/src/parser/amic.rs new file mode 100644 index 000000000..40348bd86 --- /dev/null +++ b/backend/src/parser/amic.rs @@ -0,0 +1,52 @@ +// SPDX-FileCopyrightText: Joonas Javanainen +// +// SPDX-License-Identifier: MIT + +use nom::{ + bytes::streaming::tag, + character::streaming::{char, one_of}, + combinator::{opt, recognize}, + sequence::tuple, + Parser as _, +}; + +use super::{ + for_nom::{alnum_uppers, uppers}, + GenericPart, +}; +use crate::parser::{for_nom::year2_week2, Manufacturer, NomParser}; + +/// AMIC LP62S16128 (TSOP-I-48, 2.7-3.6V) +/// +/// Source: +/// "AMIC LP62S16128BW-T series - 128k x 16 bit low voltage CMOS SRAM" +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::amic::AMIC_LP62S16128.parse("AMIC LP62S16128BW-70LLTF P4060473FB 0540A").is_ok()); +/// ``` +pub static AMIC_LP62S16128: NomParser = NomParser { + name: "AMIC LP62S16128", + f: |input| { + tuple(( + tag("AMIC "), + recognize(tuple(( + tag("LP62S16128").and(opt(one_of("ABC"))).and(tag("W")), + char('-'), + tag("70"), // speed + tag("LL"), // power + tag("TF"), + ))), + char(' '), + alnum_uppers(10), + char(' '), + year2_week2.and(uppers(1)), + )) + .map(|(_, kind, _, _, _, (date_code, _))| GenericPart { + kind: String::from(kind), + manufacturer: Some(Manufacturer::Amic), + date_code: Some(date_code), + }) + .parse(input) + }, +}; diff --git a/backend/src/parser/atmel.rs b/backend/src/parser/atmel.rs new file mode 100644 index 000000000..f02e2289d --- /dev/null +++ b/backend/src/parser/atmel.rs @@ -0,0 +1,44 @@ +// SPDX-FileCopyrightText: Joonas Javanainen +// +// SPDX-License-Identifier: MIT + +use nom::{ + bytes::streaming::tag, + character::streaming::{char, one_of}, + sequence::tuple, + Parser as _, +}; + +use super::GenericPart; +use crate::parser::{for_nom::year2_week2, Manufacturer, NomParser}; + +/// Atmel AT29LV512 (TSOP-I-32, 3.0-3.6V) +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::atmel::ATMEL_AT29LV512.parse("AT29LV512 15TC 0114").is_ok()); +/// ``` +pub static ATMEL_AT29LV512: NomParser = NomParser { + name: "Atmel AT29LV512", + f: |input| { + tuple(( + tag("AT29LV512"), + char(' '), + tuple(( + tag("15"), // speed + char('T'), // package + one_of("CI"), // grade + )), + char(' '), + year2_week2, + )) + .map( + |(kind, _, (speed, package, grade), _, date_code)| GenericPart { + kind: format!("{kind}-{speed}{package}{grade}"), + manufacturer: Some(Manufacturer::Atmel), + date_code: Some(date_code), + }, + ) + .parse(input) + }, +}; diff --git a/backend/src/parser/bsi.rs b/backend/src/parser/bsi.rs new file mode 100644 index 000000000..4ccaf92e5 --- /dev/null +++ b/backend/src/parser/bsi.rs @@ -0,0 +1,134 @@ +// SPDX-FileCopyrightText: Joonas Javanainen +// +// SPDX-License-Identifier: MIT + +use nom::{ + branch::alt, + bytes::streaming::tag, + character::streaming::{char, one_of}, + combinator::{opt, recognize}, + sequence::tuple, + Parser as _, +}; + +use super::{ + for_nom::{alnum_uppers, digits, uppers}, + GenericPart, +}; +use crate::parser::{for_nom::year2_week2, Manufacturer, NomParser}; + +/// BSI BS62LV256 (SOP-28, 2.4V-5.5V) +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::bsi::BSI_BS62LV256.parse("BSI BS62LV256SC-70 S2827V52155 A0106 TAIWAN").is_ok()); +/// assert!(parser::bsi::BSI_BS62LV256.parse("BSI BS62LV256SC-70 S2828W11075.1 F0231 TAIWAN").is_ok()); +/// assert!(parser::bsi::BSI_BS62LV256.parse("BSI BS62LV256SCG70 S2828CA30125.A D05502 TAIWAN").is_ok()); +/// assert!(parser::bsi::BSI_BS62LV256.parse("BSI BS62LV256SC-70 S2828W13088.1N F0318 TAIWAN").is_ok()); +/// ``` +pub static BSI_BS62LV256: NomParser = NomParser { + name: "BSI BS62LV256", + f: |input| { + tuple(( + tag("BSI "), + recognize(tuple(( + tag("BS62LV256"), + tag("S"), // package + one_of("CI"), // temperature + one_of("-GP"), // material + alt((tag("55"), tag("70"))), // speed + ))), + char(' '), + tuple(( + alt((tag("S2827"), tag("S2828"))), + opt(alt((tag("CA"), uppers(1)))), + digits(5), + opt(char('.').and(alnum_uppers(1)).and(opt(uppers(1)))), + )), + char(' '), + tuple((uppers(1), year2_week2, opt(digits(1)))), + tag(" TAIWAN"), + )) + .map(|(_, kind, _, _, _, (_, date_code, _), _)| GenericPart { + kind: String::from(kind), + manufacturer: Some(Manufacturer::Bsi), + date_code: Some(date_code), + }) + .parse(input) + }, +}; + +/// BSI BS616LV2018 (TSOP-I-48, 2.4-3.6V) +/// +/// Source: +/// "BSI BS616LV2018 - Very Low Power/Voltage CMOS SRAM 128k x 16 bit" +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::bsi::BSI_BS616LV2018.parse("BSI BS616LV2018TC-70 S31686-2FY24092.1 L0314 TAIWAN").is_ok()); +/// assert!(parser::bsi::BSI_BS616LV2018.parse("BSI BS616LV2018TC-70 S31686-2FY10121.1 L0230 TAIWAN").is_ok()); +/// ``` +pub static BSI_BS616LV2018: NomParser = NomParser { + name: "BSI BS616LV2018", + f: |input| { + tuple(( + tag("BSI "), + recognize(tuple(( + tag("BS616LV2018"), + tag("T"), // package + one_of("CI"), // temperature + one_of("-GP"), // material + tag("70"), // speed + ))), + char(' '), + tuple((tag("S31686-2FY"), digits(5), tag(".1"))), + char(' '), + tuple((uppers(1), year2_week2)), + tag(" TAIWAN"), + )) + .map(|(_, kind, _, _, _, (_, date_code), _)| GenericPart { + kind: String::from(kind), + manufacturer: Some(Manufacturer::Bsi), + date_code: Some(date_code), + }) + .parse(input) + }, +}; + +/// BSI BS616LV2019 (TSOP-I-48, 2.4-3.6V) +/// +/// Source: +/// "BSI BS616LV2019 - Very Low Power CMOS SRAM 128k x 16 bit" +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::bsi::BSI_BS616LV2019.parse("BSI BS616LV2019TC-70 S31687FZ26013.1 L0335 TAIWAN").is_ok()); +/// assert!(parser::bsi::BSI_BS616LV2019.parse("BSI BS616LV2019TC-70 S31687FZ27050.1 L0336 TAIWAN").is_ok()); +/// assert!(parser::bsi::BSI_BS616LV2019.parse("BSI BS616LV2019TC-70 S31687FZ31012.1 L0410 TAIWAN").is_ok()); +/// ``` +pub static BSI_BS616LV2019: NomParser = NomParser { + name: "BSI BS616LV2019", + f: |input| { + tuple(( + tag("BSI "), + recognize(tuple(( + tag("BS616LV2019"), + tag("T"), // package + one_of("CI"), // temperature + one_of("-GP"), // material + alt((tag("55"), tag("70"))), // speed + ))), + char(' '), + tuple((tag("S31687FZ"), digits(5), tag(".1"))), + char(' '), + tuple((uppers(1), year2_week2)), + tag(" TAIWAN"), + )) + .map(|(_, kind, _, _, _, (_, date_code), _)| GenericPart { + kind: String::from(kind), + manufacturer: Some(Manufacturer::Bsi), + date_code: Some(date_code), + }) + .parse(input) + }, +}; diff --git a/backend/src/parser/cgb_reg.rs b/backend/src/parser/cgb_reg.rs deleted file mode 100644 index dd5e87d83..000000000 --- a/backend/src/parser/cgb_reg.rs +++ /dev/null @@ -1,31 +0,0 @@ -// SPDX-FileCopyrightText: 2017-2023 Joonas Javanainen -// -// SPDX-License-Identifier: MIT - -use super::{week2, year2, ChipYearWeek, LabelParser}; -use crate::{macros::single_parser, parser::Manufacturer}; - -pub type CgbReg = ChipYearWeek; - -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::cgb_reg::sharp_ir3e06n().parse("CGB-REG IR3E06N 9839 C").is_ok()); -/// ``` -pub fn sharp_ir3e06n() -> &'static impl LabelParser { - single_parser!( - CgbReg, - r#"^CGB-REG\ IR3E06N\ ([0-9]{2})([0-9]{2})\ [A-Z]{1,2}$"#, - move |c| { - Ok(CgbReg { - kind: "IR3E06N".to_owned(), - manufacturer: Some(Manufacturer::Sharp), - year: Some(year2(&c[1])?), - week: Some(week2(&c[2])?), - }) - } - ) -} - -pub fn cgb_reg() -> &'static impl LabelParser { - sharp_ir3e06n() -} diff --git a/backend/src/parser/dmg_amp.rs b/backend/src/parser/dmg_amp.rs deleted file mode 100644 index 00bd85a95..000000000 --- a/backend/src/parser/dmg_amp.rs +++ /dev/null @@ -1,32 +0,0 @@ -// SPDX-FileCopyrightText: 2017-2023 Joonas Javanainen -// -// SPDX-License-Identifier: MIT - -use super::{week2, year2, ChipYearWeek, LabelParser}; -use crate::{macros::single_parser, parser::Manufacturer}; - -pub type DmgAmp = ChipYearWeek; - -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::dmg_amp::sharp_ir3r40().parse("DMG-AMP IR3R40 9222 AA").is_ok()); -/// assert!(parser::dmg_amp::sharp_ir3r40().parse("DMG-AMP IR3R40 8909 A").is_ok()); -/// ``` -pub fn sharp_ir3r40() -> &'static impl LabelParser { - single_parser!( - DmgAmp, - r#"^DMG-AMP\ IR3R40\ ([0-9]{2})([0-9]{2})\ [A-Z]{1,2}$"#, - move |c| { - Ok(DmgAmp { - kind: "IR3R40".to_owned(), - manufacturer: Some(Manufacturer::Sharp), - year: Some(year2(&c[1])?), - week: Some(week2(&c[2])?), - }) - }, - ) -} - -pub fn dmg_amp() -> &'static impl LabelParser { - sharp_ir3r40() -} diff --git a/backend/src/parser/dmg_reg.rs b/backend/src/parser/dmg_reg.rs deleted file mode 100644 index ef250fe94..000000000 --- a/backend/src/parser/dmg_reg.rs +++ /dev/null @@ -1,33 +0,0 @@ -// SPDX-FileCopyrightText: 2017-2023 Joonas Javanainen -// -// SPDX-License-Identifier: MIT - -use super::{week2, year2, ChipYearWeek, LabelParser}; -use crate::{macros::single_parser, parser::Manufacturer}; - -pub type DmgReg = ChipYearWeek; - -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::dmg_reg::sharp_ir3e02().parse("DMG-REG IR3E02 9527 CB").is_ok()); -/// assert!(parser::dmg_reg::sharp_ir3e02().parse("DMG-REG IR3E02 9820 n").is_ok()); -/// assert!(parser::dmg_reg::sharp_ir3e02().parse("DMG-REG IR3E02 9024 J").is_ok()); -/// ``` -pub fn sharp_ir3e02() -> &'static impl LabelParser { - single_parser!( - DmgReg, - r#"^DMG-REG\ IR3E02\ ([0-9]{2})([0-9]{2})\ [a-zA-Z]{1,2}$"#, - move |c| { - Ok(DmgReg { - kind: "IR3E02".to_owned(), - manufacturer: Some(Manufacturer::Sharp), - year: Some(year2(&c[1])?), - week: Some(week2(&c[2])?), - }) - }, - ) -} - -pub fn dmg_reg() -> &'static impl LabelParser { - sharp_ir3e02() -} diff --git a/backend/src/parser/eeprom.rs b/backend/src/parser/eeprom.rs index 43581310b..974dc6193 100644 --- a/backend/src/parser/eeprom.rs +++ b/backend/src/parser/eeprom.rs @@ -2,79 +2,58 @@ // // SPDX-License-Identifier: MIT -use super::{week2, year1, ChipYearWeek, LabelParser}; -use crate::macros::{multi_parser, single_parser}; +use nom::{ + bytes::streaming::tag, character::streaming::char, combinator::opt, sequence::tuple, + Parser as _, +}; -pub type Eeprom = ChipYearWeek; +use super::{ + for_nom::{digits, uppers, year1_week2}, + GenericPart, LabelParser, NomParser, +}; +use crate::{macros::multi_parser, parser::rohm}; -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::eeprom::lcs5().parse("LCS5 040").is_ok()); -/// ``` -pub fn lcs5() -> &'static impl LabelParser { - single_parser!( - Eeprom, - r#"^LCS5\ ([0-9])([0-9]{2})(\ [0-9]{2})?$"#, - move |c| { - Ok(Eeprom { - kind: "LCS5".to_owned(), - manufacturer: None, - year: Some(year1(&c[1])?), - week: Some(week2(&c[2])?), - }) - } - ) -} +pub type Eeprom = GenericPart; /// ``` /// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::eeprom::lc56().parse("LC56 W617 08").is_ok()); -/// ``` -pub fn lc56() -> &'static impl LabelParser { - single_parser!(Eeprom, r#"^LC56\ [A-Z][0-9]{3}\ [0-9]{2}$"#, move |_| { - Ok(Eeprom { +/// assert!(parser::eeprom::LCS5.parse("LCS5 040").is_ok()); +/// assert!(parser::eeprom::LCS5.parse("LCS5 435 09").is_ok()); +/// ``` +pub static LCS5: NomParser = NomParser { + name: "LCS5", + f: |input| { + tuple(( + tag("LCS5 "), + year1_week2, + opt(tuple((nom::character::complete::char(' '), digits(2)))), + )) + .map(|(_, date_code, _)| Eeprom { kind: "LC56".to_owned(), manufacturer: None, - year: None, - week: None, - }) - }) -} - -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::eeprom::unknown_9853().parse("9853 2A46").is_ok()); -/// assert!(parser::eeprom::unknown_9853().parse("9853 6912").is_ok()); -/// ``` -pub fn unknown_9853() -> &'static impl LabelParser { - single_parser!(Eeprom, r#"^9853\ ([0-9])[[:alnum:]][0-9]{2}$"#, move |c| { - Ok(Eeprom { - kind: "9853".to_owned(), - manufacturer: None, - year: Some(year1(&c[1])?), - week: None, + date_code: Some(date_code), }) - }) -} + .parse(input) + }, +}; /// ``` /// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::eeprom::unknown_9854().parse("9854 5S95W").is_ok()); -/// ``` -pub fn unknown_9854() -> &'static impl LabelParser { - single_parser!( - Eeprom, - r#"^9854\ ([0-9])[[:alnum:]][0-9]{2}[A-Z]$"#, - move |c| { - Ok(Eeprom { - kind: "9854".to_owned(), +/// assert!(parser::eeprom::LC56.parse("LC56 W617 08").is_ok()); +/// ``` +pub static LC56: NomParser = NomParser { + name: "LC56", + f: |input| { + tuple((tag("LC56 "), uppers(1).and(digits(3)), char(' '), digits(2))) + .map(|(_, _, _, _)| Eeprom { + kind: "LC56".to_owned(), manufacturer: None, - year: Some(year1(&c[1])?), - week: None, + date_code: None, }) - } - ) -} + .parse(input) + }, +}; + pub fn eeprom() -> &'static impl LabelParser { - multi_parser!(Eeprom, lcs5(), lc56(), unknown_9853(), unknown_9854()) + multi_parser!(Eeprom, &LCS5, &LC56, &rohm::ROHM_9853, &rohm::ROHM_9854) } diff --git a/backend/src/parser/flash.rs b/backend/src/parser/flash.rs deleted file mode 100644 index 54676caa0..000000000 --- a/backend/src/parser/flash.rs +++ /dev/null @@ -1,25 +0,0 @@ -// SPDX-FileCopyrightText: 2017-2023 Joonas Javanainen -// -// SPDX-License-Identifier: MIT - -use super::{GenericChip, LabelParser}; -use crate::macros::multi_parser; - -pub mod tsop_i_32; -pub mod tsop_i_40; - -pub type Flash = GenericChip; - -pub fn flash_tsop_i_32() -> &'static impl LabelParser { - multi_parser!( - Flash, - &tsop_i_32::MACRONIX_MX29L010, - &tsop_i_32::SANYO_LE26FV10, - &tsop_i_32::ATMEL_AT29LV512, - &tsop_i_32::SST_SST39VF512, - ) -} - -pub fn flash_tsop_i_40() -> &'static impl LabelParser { - multi_parser!(Flash, &tsop_i_40::MACRONIX_MX29F008) -} diff --git a/backend/src/parser/flash/tsop_i_32.rs b/backend/src/parser/flash/tsop_i_32.rs deleted file mode 100644 index 987a2f457..000000000 --- a/backend/src/parser/flash/tsop_i_32.rs +++ /dev/null @@ -1,132 +0,0 @@ -// SPDX-FileCopyrightText: 2017-2023 Joonas Javanainen -// -// SPDX-License-Identifier: MIT - -use nom::{ - bytes::streaming::tag, - character::streaming::{char, one_of}, - combinator::opt, - sequence::tuple, - Parser as _, -}; - -use super::Flash; -use crate::parser::{ - for_nom::{alnum_uppers, digits, month1_alpha, uppers, year1, year2_week2}, - macronix, ChipDateCode, Manufacturer, NomParser, -}; - -/// Macronix MX29L010 (TSOP-I-32) -/// -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::flash::tsop_i_32::MACRONIX_MX29L010.parse("B063857G MX29L010TC-15A1 1H4751").is_ok()); -/// assert!(parser::flash::tsop_i_32::MACRONIX_MX29L010.parse("E032457 MX29L010TC-15A1 1E8980").is_ok()); -/// assert!(parser::flash::tsop_i_32::MACRONIX_MX29L010.parse("E023057 MX29L010TC-15 1E0290").is_ok()); -/// assert!(parser::flash::tsop_i_32::MACRONIX_MX29L010.parse("E040257 MX29L010TC-15A1 1F468900A0").is_ok()); -/// ``` -pub static MACRONIX_MX29L010: NomParser = NomParser { - name: "Macronix MX29L010", - f: |input| { - tuple(( - macronix::assembly_vendor_code, - macronix::date_code, - tag("57"), // digits 3 and 4 of "product body" (?) - opt(tag("G")), // green package? - tag(" MX29L010TC-15"), - opt(tag("A1")), // revision? - char(' '), - macronix::lot_code_new, - )) - .map(|(_, date_code, _, _, _, _, _, _)| Flash { - kind: String::from("MX29L010TC-15"), - manufacturer: Some(Manufacturer::Macronix), - date_code: Some(date_code), - }) - .parse(input) - }, -}; - -/// Sanyo LE26FV10 (TSOP-I-32) -/// -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::flash::tsop_i_32::SANYO_LE26FV10.parse("LE26FV10N1TS-10 3MU50").is_ok()); -/// assert!(parser::flash::tsop_i_32::SANYO_LE26FV10.parse("LE26FV10N1TS-10 4DU2A").is_ok()); -/// ``` -pub static SANYO_LE26FV10: NomParser = NomParser { - name: "Sanyo LE26FV10", - f: |input| { - tuple(( - tag("LE26FV10N1"), - tag("TS-10"), // package, speed - char(' '), - year1, - month1_alpha, - uppers(1), - digits(1), - alnum_uppers(1), - )) - .map(|(kind, attrs, _, year, month, _, _, _)| Flash { - kind: format!("{kind}{attrs}"), - manufacturer: Some(Manufacturer::Sanyo), - date_code: Some(ChipDateCode::YearMonth { year, month }), - }) - .parse(input) - }, -}; - -/// Atmel AT29LV512 (TSOP-I-32) -/// -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::flash::tsop_i_32::ATMEL_AT29LV512.parse("AT29LV512 15TC 0114").is_ok()); -/// ``` -pub static ATMEL_AT29LV512: NomParser = NomParser { - name: "Atmel AT29LV512", - f: |input| { - tuple(( - tag("AT29LV512"), - char(' '), - tag("15"), // speed - char('T'), // package - one_of("CI"), // grade - char(' '), - year2_week2, - )) - .map(|(kind, _, speed, package, grade, _, date_code)| Flash { - kind: format!("{kind}-{speed}{package}{grade}"), - manufacturer: Some(Manufacturer::Atmel), - date_code: Some(date_code), - }) - .parse(input) - }, -}; - -/// SST SST39VF512 (TSOP-I-32) -/// -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::flash::tsop_i_32::SST_SST39VF512.parse("39VF512 70-4C-WH 0216049-D").is_ok()); -/// assert!(parser::flash::tsop_i_32::SST_SST39VF512.parse("39VF512 70-4C-WH 0350077-D").is_ok()); -/// ``` -pub static SST_SST39VF512: NomParser = NomParser { - name: "SST SST39VF512", - f: |input| { - tuple(( - tag("39VF512"), - char(' '), - tag("70-4C-WH"), // speed, durability, grade, package - char(' '), - year2_week2, - digits(3), - tag("-D"), - )) - .map(|(kind, _, attrs, _, date_code, _, _)| Flash { - kind: format!("SST{kind}-{attrs}"), - manufacturer: Some(Manufacturer::Sst), - date_code: Some(date_code), - }) - .parse(input) - }, -}; diff --git a/backend/src/parser/flash/tsop_i_40.rs b/backend/src/parser/flash/tsop_i_40.rs deleted file mode 100644 index 9410598ac..000000000 --- a/backend/src/parser/flash/tsop_i_40.rs +++ /dev/null @@ -1,35 +0,0 @@ -// SPDX-FileCopyrightText: 2017-2023 Joonas Javanainen -// -// SPDX-License-Identifier: MIT - -use nom::{bytes::streaming::tag, character::streaming::char, sequence::tuple, Parser as _}; - -use super::Flash; -use crate::parser::{macronix, Manufacturer, NomParser}; - -/// Macronix MX29F008 (TSOP-I-40) -/// -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::flash::tsop_i_40::MACRONIX_MX29F008.parse("E991012 29F008TC-14 21534 TAIWAN").is_ok()); -/// ``` -pub static MACRONIX_MX29F008: NomParser = NomParser { - name: "Macronix MX29F008", - f: |input| { - tuple(( - macronix::assembly_vendor_code, - macronix::date_code, - tag("12"), // digits 3 and 4 of "product body" (?) - tag(" 29F008TC-14"), - char(' '), - macronix::lot_code_old, - tag(" TAIWAN"), - )) - .map(|(_, date_code, _, _, _, _, _)| Flash { - kind: String::from("MX29F008TC-14"), - manufacturer: Some(Manufacturer::Macronix), - date_code: Some(date_code), - }) - .parse(input) - }, -}; diff --git a/backend/src/parser/fram.rs b/backend/src/parser/fram.rs deleted file mode 100644 index 9ea76a8d9..000000000 --- a/backend/src/parser/fram.rs +++ /dev/null @@ -1,63 +0,0 @@ -// SPDX-FileCopyrightText: 2017-2023 Joonas Javanainen -// -// SPDX-License-Identifier: MIT - -use crate::{ - macros::multi_parser, - parser::{GenericChip, LabelParser}, -}; - -pub mod sop_28 { - use nom::{ - bytes::streaming::tag, - character::{complete::one_of, streaming::char}, - combinator::opt, - sequence::tuple, - Parser as _, - }; - - use super::Fram; - use crate::parser::{ - for_nom::{digits, uppers, year2_week2}, - Manufacturer, NomParser, - }; - - /// Fujitsu MB85R256 (SOP-28) - /// - /// ``` - /// use gbhwdb_backend::parser::{self, LabelParser}; - /// assert!(parser::fram::sop_28::FUJITSU_MB85R256.parse("JAPAN MB85R256A 0412 M88").is_ok()); - /// assert!(parser::fram::sop_28::FUJITSU_MB85R256.parse("JAPAN MB85R256S 0511 M22 E1").is_ok()); - /// ``` - pub static FUJITSU_MB85R256: NomParser = NomParser { - name: "Fujitsu MB85R256", - f: |input| { - tuple(( - tag("JAPAN "), - tag("MB85R256"), - opt(one_of("AS")), - char(' '), - year2_week2, - char(' '), - uppers(1), - digits(2), - opt(nom::bytes::complete::tag(" E1")), - )) - .map(|(_, kind, rev, _, date_code, _, _, _, _)| Fram { - kind: match rev { - None => String::from(kind), - Some(rev) => format!("{kind}{rev}"), - }, - manufacturer: Some(Manufacturer::Fujitsu), - date_code: Some(date_code), - }) - .parse(input) - }, - }; -} - -pub type Fram = GenericChip; - -pub fn fram_sop_28() -> &'static impl LabelParser { - multi_parser!(Fram, &sop_28::FUJITSU_MB85R256,) -} diff --git a/backend/src/parser/fujitsu.rs b/backend/src/parser/fujitsu.rs new file mode 100644 index 000000000..7266e2fb4 --- /dev/null +++ b/backend/src/parser/fujitsu.rs @@ -0,0 +1,112 @@ +// SPDX-FileCopyrightText: Joonas Javanainen +// +// SPDX-License-Identifier: MIT + +use nom::{ + branch::alt, + bytes::streaming::tag, + character::{complete::one_of, streaming::char}, + combinator::{opt, recognize}, + sequence::tuple, + Parser as _, +}; + +use crate::parser::{ + for_nom::{digits, uppers, year2_week2}, + Manufacturer, NomParser, +}; + +use super::{ + for_nom::{alnum_uppers, cgb_rom_code, dmg_rom_code}, + GenericPart, MaskRom, +}; + +/// Fujitsu MB85R256 (SOP-28, 3.0-3.6V) +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::fujitsu::FUJITSU_MB85R256.parse("JAPAN MB85R256A 0412 M88").is_ok()); +/// assert!(parser::fujitsu::FUJITSU_MB85R256.parse("JAPAN MB85R256S 0511 M22 E1").is_ok()); +/// ``` +pub static FUJITSU_MB85R256: NomParser = NomParser { + name: "Fujitsu MB85R256", + f: |input| { + tuple(( + tag("JAPAN "), + recognize(tag("MB85R256").and(opt(one_of("AS")))), + char(' '), + year2_week2, + char(' '), + uppers(1).and(digits(2)), + opt(nom::bytes::complete::tag(" E1")), + )) + .map(|(_, kind, _, date_code, _, _, _)| GenericPart { + kind: String::from(kind), + manufacturer: Some(Manufacturer::Fujitsu), + date_code: Some(date_code), + }) + .parse(input) + }, +}; + +/// Fujitsu MB82D12160 (TSOP-I-48) +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::fujitsu::FUJITSU_MB82D12160.parse("JAPAN 82D12160-10FN 0238 M88N").is_ok()); +/// ``` +pub static FUJITSU_MB82D12160: NomParser = NomParser { + name: "Fujitsu MB82D12160", + f: |input| { + tuple(( + tag("JAPAN "), + tag("82D12160-10FN"), + char(' '), + year2_week2, + char(' '), + uppers(1).and(digits(2)).and(uppers(1)), + )) + .map(|(_, kind, _, date_code, _, _)| GenericPart { + kind: format!("MB{kind}"), + manufacturer: Some(Manufacturer::Fujitsu), + date_code: Some(date_code), + }) + .parse(input) + }, +}; + +/// Fujitsu mask ROM (SOP-32, 5V) +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::fujitsu::FUJITSU_MASK_ROM.parse("JAPAN DMG-GKX-0 D1 1P0 AK 9328 R09").is_ok()); +/// assert!(parser::fujitsu::FUJITSU_MASK_ROM.parse("JAPAN DMG-WJA-0 E1 3NH AK 9401 R17").is_ok()); +/// ``` +pub static FUJITSU_MASK_ROM: NomParser = NomParser { + name: "Fujitsu mask ROM", + f: |input| { + tuple(( + tag("JAPAN "), + alt((dmg_rom_code(), cgb_rom_code())), + char(' '), + uppers(1).and(digits(1)), + char(' '), + digits(1).and(uppers(1)).and(alnum_uppers(1)), + char(' '), + tag("AK"), + char(' '), + year2_week2, + char(' '), + uppers(1).and(digits(2)), + )) + .map( + |(_, rom_id, _, _, _, _, _, _, _, date_code, _, _)| MaskRom { + rom_id: String::from(rom_id), + manufacturer: Some(Manufacturer::Fujitsu), + chip_type: None, + date_code: Some(date_code), + }, + ) + .parse(input) + }, +}; diff --git a/backend/src/parser/gbs_reg.rs b/backend/src/parser/gbs_reg.rs deleted file mode 100644 index 413ab4791..000000000 --- a/backend/src/parser/gbs_reg.rs +++ /dev/null @@ -1,27 +0,0 @@ -// SPDX-FileCopyrightText: 2017-2023 Joonas Javanainen -// -// SPDX-License-Identifier: MIT - -use super::{week2, year1, ChipYearWeek, LabelParser, Manufacturer}; -use crate::macros::single_parser; - -pub type GbsReg = ChipYearWeek; - -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::gbs_reg::mitsumi_mm1592f().parse("548 592F").is_ok()); -/// ``` -pub fn mitsumi_mm1592f() -> &'static impl LabelParser { - single_parser!(GbsReg, r#"^([0-9])([0-9]{2})\ 592F$"#, move |c| { - Ok(GbsReg { - kind: "MM1592F".to_owned(), - manufacturer: Some(Manufacturer::Mitsumi), - year: Some(year1(&c[1])?), - week: Some(week2(&c[2])?), - }) - }) -} - -pub fn gbs_reg() -> &'static impl LabelParser { - mitsumi_mm1592f() -} diff --git a/backend/src/parser/hex_inverter.rs b/backend/src/parser/hex_inverter.rs deleted file mode 100644 index f56890f5f..000000000 --- a/backend/src/parser/hex_inverter.rs +++ /dev/null @@ -1,27 +0,0 @@ -// SPDX-FileCopyrightText: 2017-2023 Joonas Javanainen -// -// SPDX-License-Identifier: MIT - -use super::{week2, year1, ChipYearWeek, LabelParser, Manufacturer}; -use crate::macros::single_parser; - -pub type HexInverter = ChipYearWeek; - -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::hex_inverter::toshiba_tc74lvx04ft().parse("LVX 04 8 45").is_ok()); -/// ``` -pub fn toshiba_tc74lvx04ft() -> &'static impl LabelParser { - single_parser!(HexInverter, r#"^LVX\ 04\ ([0-9])\ ([0-9]{2})$"#, move |c| { - Ok(HexInverter { - kind: "TC74LVX04FT".to_owned(), - manufacturer: Some(Manufacturer::Toshiba), - year: Some(year1(&c[1])?), - week: Some(week2(&c[2])?), - }) - }) -} - -pub fn hex_inverter() -> &'static impl LabelParser { - toshiba_tc74lvx04ft() -} diff --git a/backend/src/parser/hynix.rs b/backend/src/parser/hynix.rs new file mode 100644 index 000000000..16116daac --- /dev/null +++ b/backend/src/parser/hynix.rs @@ -0,0 +1,99 @@ +// SPDX-FileCopyrightText: Joonas Javanainen +// +// SPDX-License-Identifier: MIT + +use nom::{ + branch::alt, + bytes::streaming::tag, + character::streaming::{char, one_of}, + combinator::{opt, recognize, value}, + error::ParseError, + sequence::tuple, + IResult, Parser, +}; + +use super::{ + for_nom::{uppers, year2_week2}, + sram::Ram, + PartDateCode, +}; +use crate::parser::{Manufacturer, NomParser}; + +/// Hynix HY62LF16206 (TSOP-I-48, 2.3-2.7V) +/// +/// Source: +/// "hynix HY62LF16206A-LT12C 128kx16bit full CMOS SRAM" +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::hynix::HYNIX_HY62LF16206.parse("Hynix KOREA HY62LF16206A 0223A LT12C").is_ok()); +/// ``` +pub static HYNIX_HY62LF16206: NomParser = NomParser { + name: "Hynix HY62LF16206", + f: |input| { + tuple(( + tag("Hynix KOREA "), + recognize(tag("HY62LF16206").and(opt(one_of("AB")))), + char(' '), + date_code.and(process_code), + char(' '), + tuple(( + tag("L"), // power + tag("T"), // package + tag("12"), // speed + tag("C"), // temperature + )), + )) + .map( + |(_, kind, _, (date_code, _), _, (power, package, speed, temp))| Ram { + kind: format!("{kind}-{power}{package}{speed}{temp}"), + manufacturer: Some(Manufacturer::Hynix), + date_code: Some(date_code), + }, + ) + .parse(input) + }, +}; + +/// Hynix HY62WT08081 (SOP-28, 2.7-5.5V) +/// +/// Source: +/// "hynix HY62WT08081E Series 32Kx8bit CMOS SRAM" +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::hynix::HYNIX_HY62WT08081.parse("hynix 0231A HY62WT081ED70C KOREA").is_ok()); +/// ``` +pub static HYNIX_HY62WT08081: NomParser = NomParser { + name: "Hynix HY62WT08081", + f: |input| { + tuple(( + tag("hynix "), + date_code.and(process_code), + char(' '), + tuple(( + recognize(value("HY62WT08081", tag("HY62WT081")).and(opt(one_of("ABCDE")))), + alt((tag("L"), tag("D"))), // power + alt((tag("50"), tag("70"))), // speed + alt((tag("C"), tag("E"), tag("I"))), // temperature + )), + tag(" KOREA"), + )) + .map( + |(_, (date_code, _), _, (kind, power, speed, temp), _)| Ram { + kind: format!("{kind}{power}{speed}{temp}"), + manufacturer: Some(Manufacturer::Hynix), + date_code: Some(date_code), + }, + ) + .parse(input) + }, +}; + +fn date_code<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&'a str, PartDateCode, E> { + year2_week2(input) +} + +fn process_code<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&'a str, &str, E> { + uppers(1).parse(input) +} diff --git a/backend/src/parser/hyundai.rs b/backend/src/parser/hyundai.rs new file mode 100644 index 000000000..3a8fbb030 --- /dev/null +++ b/backend/src/parser/hyundai.rs @@ -0,0 +1,131 @@ +// SPDX-FileCopyrightText: Joonas Javanainen +// +// SPDX-License-Identifier: MIT + +use nom::{ + branch::alt, bytes::streaming::tag, character::streaming::char, combinator::value, + error::ParseError, sequence::tuple, IResult, Parser, +}; + +use super::{ + for_nom::{uppers, year2_week2}, + sram::Ram, + PartDateCode, +}; +use crate::parser::{Manufacturer, NomParser}; + +/// Hyundai HY628100 (SOP-32, 4.5-5.5V) +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::hyundai::HYUNDAI_HY628100.parse("HYUNDAI KOREA HY628100B 0041A LLG-70").is_ok()); +/// ``` +pub static HYUNDAI_HY628100: NomParser = NomParser { + name: "Hyundai HY628100", + f: |input| { + tuple(( + tag("HYUNDAI KOREA "), + alt((tag("HY628100A"), tag("HY628100B"), tag("HY628100"))), + char(' '), + date_code.and(process_code), + char(' '), + tuple(( + alt((tag("LL"), tag("L"))), // power + package(Package::Sop32), // package + char('-'), + alt((tag("50"), tag("55"), tag("70"), tag("85"))), // speed + )), + )) + .map( + |(_, kind, _, (date_code, _), _, (power, package, _, speed))| Ram { + kind: format!("{kind}{power}{package}-{speed}", package = package.code()), + manufacturer: Some(Manufacturer::Hyundai), + date_code: Some(date_code), + }, + ) + .parse(input) + }, +}; + +/// Hyundai HY6264 (SOP-28, 4.5-5.5V) +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::hyundai::HYUNDAI_HY6264.parse("HYUNDAI HY6264ALLJ-10 9327B KOREA").is_ok()); +/// assert!(parser::hyundai::HYUNDAI_HY6264.parse("HY6264A LLJ-10 9902B KOREA").is_ok()); +/// ``` +pub static HYUNDAI_HY6264: NomParser = NomParser { + name: "Hyundai HY6264", + f: |input| { + // 1992-1994 + let old_format = tuple(( + tag("HYUNDAI "), + tuple(( + alt((tag("HY6264A"), tag("HY6264"))), + alt((tag("LL"), tag("L"))), // power + package(Package::Sop28), // package + char('-'), + alt((tag("70"), tag("85"), tag("10"), tag("12"), tag("15"))), // speed + )), + char(' '), + date_code.and(process_code), + tag(" KOREA"), + )) + .map( + |(_, (kind, power, package, _, speed), _, (date_code, _), _)| Ram { + kind: format!("{kind}{power}{package}-{speed}", package = package.code()), + manufacturer: Some(Manufacturer::Hyundai), + date_code: Some(date_code), + }, + ); + // 1994- + let new_format = tuple(( + alt((tag("HY6264A"), tag("HY6264"))), + char(' '), + tuple(( + alt((tag("LL"), tag("L"))), // power + package(Package::Sop28), // package + char('-'), + alt((tag("70"), tag("85"), tag("10"), tag("12"), tag("15"))), // speed + )), + char(' '), + date_code.and(process_code), + tag(" KOREA"), + )) + .map( + |(kind, _, (power, package, _, speed), _, (date_code, _), _)| Ram { + kind: format!("{kind}{power}{package}-{speed}", package = package.code()), + manufacturer: Some(Manufacturer::Hyundai), + date_code: Some(date_code), + }, + ); + alt((new_format, old_format)).parse(input) + }, +}; + +fn date_code<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&'a str, PartDateCode, E> { + year2_week2(input) +} + +fn process_code<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&'a str, &str, E> { + uppers(1).parse(input) +} + +fn package<'a, E: ParseError<&'a str>>(package: Package) -> impl Parser<&'a str, Package, E> { + value(package, tag(package.code())) +} + +#[derive(Copy, Clone, Debug, PartialEq, Eq)] +enum Package { + Sop28, + Sop32, +} + +impl Package { + pub const fn code(&self) -> &'static str { + match self { + Package::Sop28 => "J", + Package::Sop32 => "G", + } + } +} diff --git a/backend/src/parser/lgs.rs b/backend/src/parser/lgs.rs new file mode 100644 index 000000000..2b843827f --- /dev/null +++ b/backend/src/parser/lgs.rs @@ -0,0 +1,124 @@ +// SPDX-FileCopyrightText: Joonas Javanainen +// +// SPDX-License-Identifier: MIT + +use nom::{ + branch::alt, + bytes::streaming::tag, + character::streaming::{char, one_of}, + combinator::{opt, recognize}, + sequence::tuple, + Parser as _, +}; + +use super::{for_nom::year2_week2, sram::Ram, Manufacturer, NomParser}; + +/// LGS GM76C256 (SOP-28, 5V) +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::lgs::LGS_GM76C256.parse("LGS GM76C256CLLFW70 0047 KOREA").is_ok()); +/// ``` +pub static LGS_GM76C256: NomParser = NomParser { + name: "LGS GM76C256", + f: |input| { + let package = Package::Sop; + tuple(( + tag("LGS "), + tuple(( + recognize(tag("GM76C256").and(opt(one_of("ABC")))), + alt((tag("LL"), tag("L"))), // power + tag(package.code()), // package + alt((tag("70"), tag("85"), tag("10"))), // speed + )), + char(' '), + year2_week2, + tag(" KOREA"), + )) + .map(|(_, (kind, power, package, speed), _, date_code, _)| Ram { + kind: format!("{kind}{power}{package}{speed}"), + manufacturer: Some(Manufacturer::Lgs), + date_code: Some(date_code), + }) + .parse(input) + }, +}; + +/// Hyundai GM76C256 (SOP-28, 5V) +/// +/// Originally by LGS, acquired by Hyundai +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::lgs::HYUNDAI_GM76C256.parse("HYUNDAI GM76C256CLLFW70 0047 KOREA").is_ok()); +/// ``` +pub static HYUNDAI_GM76C256: NomParser = NomParser { + name: "Hyundai GM76C256", + f: |input| { + let package = Package::Sop; + tuple(( + tag("HYUNDAI "), + tuple(( + recognize(tag("GM76C256").and(opt(one_of("ABC")))), + alt((tag("LL"), tag("L"))), // power + tag(package.code()), // package + alt((tag("70"), tag("85"), tag("10"))), // speed + )), + char(' '), + year2_week2, + tag(" KOREA"), + )) + .map(|(_, (kind, power, package, speed), _, date_code, _)| Ram { + kind: format!("{kind}{power}{package}{speed}"), + manufacturer: Some(Manufacturer::Hyundai), + date_code: Some(date_code), + }) + .parse(input) + }, +}; + +/// Hyundai GM76V256 (SOP-28, 2.5-3.6V) +/// +/// Originally by LGS, acquired by Hyundai +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::lgs::HYUNDAI_GM76V256.parse("HYUNDAI GM76V256CLLFW10 0115 KOREA").is_ok()); +/// ``` +pub static HYUNDAI_GM76V256: NomParser = NomParser { + name: "Hyundai GM76V256", + f: |input| { + let package = Package::Sop; + tuple(( + tag("HYUNDAI "), + tuple(( + recognize(tag("GM76V256").and(opt(one_of("ABC")))), + alt((tag("LL"), tag("L"))), // power + tag(package.code()), // package + tag("10"), // speed + )), + char(' '), + year2_week2, + tag(" KOREA"), + )) + .map(|(_, (kind, power, package, speed), _, date_code, _)| Ram { + kind: format!("{kind}{power}{package}{speed}"), + manufacturer: Some(Manufacturer::Hyundai), + date_code: Some(date_code), + }) + .parse(input) + }, +}; + +#[derive(Copy, Clone, Debug, PartialEq, Eq)] +enum Package { + Sop, +} + +impl Package { + pub const fn code(&self) -> &'static str { + match self { + Package::Sop => "FW", + } + } +} diff --git a/backend/src/parser/line_decoder.rs b/backend/src/parser/line_decoder.rs deleted file mode 100644 index 308cae474..000000000 --- a/backend/src/parser/line_decoder.rs +++ /dev/null @@ -1,33 +0,0 @@ -// SPDX-FileCopyrightText: 2017-2023 Joonas Javanainen -// -// SPDX-License-Identifier: MIT - -use super::{year1, ChipYearWeek, LabelParser, Manufacturer}; -use crate::macros::single_parser; - -pub type LineDecoder = ChipYearWeek; - -/// Toshiba TC7W139F -/// -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::line_decoder::toshiba_tc7w139f().parse("7W139 0J").is_ok()); -/// ``` -pub fn toshiba_tc7w139f() -> &'static impl LabelParser { - single_parser!(LineDecoder, r#"^(7W139F?)\ ([0-9])[A-Z]$"#, move |c| { - Ok(LineDecoder { - kind: (match &c[1] { - "7W139" => Ok("TC7W139FU".to_owned()), - "7W139F" => Ok("TC7W139F".to_owned()), - text => Err(format!("Invalid Toshiba TC7W139F part name: {}", text)), - })?, - manufacturer: Some(Manufacturer::Toshiba), - year: Some(year1(&c[2])?), - week: None, - }) - }) -} - -pub fn line_decoder() -> &'static impl LabelParser { - toshiba_tc7w139f() -} diff --git a/backend/src/parser/macronix.rs b/backend/src/parser/macronix.rs new file mode 100644 index 000000000..dbecb3e7e --- /dev/null +++ b/backend/src/parser/macronix.rs @@ -0,0 +1,381 @@ +// SPDX-FileCopyrightText: Joonas Javanainen +// +// SPDX-License-Identifier: MIT + +use nom::{ + branch::alt, + bytes::streaming::tag, + character::streaming::{char, satisfy}, + combinator::{opt, recognize}, + error::ParseError, + sequence::tuple, + IResult, Parser, +}; + +use super::{ + for_nom::{self, agb_rom_code, alnum_uppers, cgb_rom_code, digits, dmg_rom_code, uppers}, + GenericPart, Manufacturer, MaskRom, NomParser, PartDateCode, +}; + +/// Macronix MX29F008 (TSOP-I-40, 4.5-5.5V) +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::macronix::MACRONIX_MX29F008.parse("E991012 29F008TC-14 21534 TAIWAN").is_ok()); +/// ``` +pub static MACRONIX_MX29F008: NomParser = NomParser { + name: "Macronix MX29F008", + f: |input| { + tuple(( + tuple(( + assembly_vendor_code, + date_code, + tag("12"), // digits 3 and 4 of "product body" (?) + )), + char(' '), + tag("29F008TC-14"), + char(' '), + lot_code_old, + tag(" TAIWAN"), + )) + .map(|((_, date_code, _), _, kind, _, _, _)| GenericPart { + kind: format!("MX{kind}"), + manufacturer: Some(Manufacturer::Macronix), + date_code: Some(date_code), + }) + .parse(input) + }, +}; + +/// Macronix MX29L010 (TSOP-I-32, 3.3V) +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::macronix::MACRONIX_MX29L010.parse("B063857G MX29L010TC-15A1 1H4751").is_ok()); +/// assert!(parser::macronix::MACRONIX_MX29L010.parse("E032457 MX29L010TC-15A1 1E8980").is_ok()); +/// assert!(parser::macronix::MACRONIX_MX29L010.parse("E023057 MX29L010TC-15 1E0290").is_ok()); +/// assert!(parser::macronix::MACRONIX_MX29L010.parse("E040257 MX29L010TC-15A1 1F468900A0").is_ok()); +/// ``` +pub static MACRONIX_MX29L010: NomParser = NomParser { + name: "Macronix MX29L010", + f: |input| { + tuple(( + tuple(( + assembly_vendor_code, + date_code, + tag("57"), // digits 3 and 4 of "product body" (?) + opt(tag("G")), // green package? + )), + char(' '), + alt((tag("MX29L010TC-15A1"), tag("MX29L010TC-15"))), + char(' '), + lot_code_new, + )) + .map(|((_, date_code, _, _), _, kind, _, _)| GenericPart { + kind: String::from(kind), + manufacturer: Some(Manufacturer::Macronix), + date_code: Some(date_code), + }) + .parse(input) + }, +}; + +fn agb_mx23l<'a, E: ParseError<&'a str>>( + chip_type: &'static str, + product_body: &'static str, + unknown: &'static str, +) -> impl Parser<&'a str, MaskRom, E> { + tuple(( + assembly_vendor_code, + date_code, + tag(product_body), + tag("-M"), + opt(tag("G")), // green package? + char(' '), + tag(chip_type), + char(' '), + agb_rom_code(), + char(' '), + tag(unknown), + char(' '), + lot_code_new, + )) + .map( + |(_, date_code, _, _, _, _, kind, _, rom_id, _, _, _, _)| MaskRom { + rom_id: String::from(rom_id), + chip_type: Some(String::from(kind)), + manufacturer: Some(Manufacturer::Macronix), + date_code: Some(date_code), + }, + ) +} + +/// Macronix MX23L2306 (TSOP-II-44, 3.3V) +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::macronix::MACRONIX_MX23L3206.parse("M043821-M MX23L3206-12B AGB-BP9E-0 H2 2K194300").is_ok()); +/// assert!(parser::macronix::MACRONIX_MX23L3206.parse("S064421-MG MX23L3206-12B AGB-BG7E-0 H2 2T341304").is_ok()); +/// ``` +pub static MACRONIX_MX23L3206: NomParser = NomParser { + name: "Macronix MX23L3206", + f: |input| agb_mx23l("MX23L3206-12B", "21", "H2").parse(input), +}; + +/// Macronix MX23L6406 (TSOP-II-44, 3.3V) +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::macronix::MACRONIX_MX23L6406.parse("M022807-M MX23L6406-12B1 AGB-AGSF-0 I2 2E825103").is_ok()); +/// assert!(parser::macronix::MACRONIX_MX23L6406.parse("S051746-MG MX23L6406-12C AGB-BRKP-0 I2 2L261801").is_ok()); +/// ``` +pub static MACRONIX_MX23L6406: NomParser = NomParser { + name: "Macronix MX23L6406", + f: |input| { + alt(( + agb_mx23l("MX23L6406-12B", "07", "I2"), + agb_mx23l("MX23L6406-12B1", "07", "I2"), + agb_mx23l("MX23L6406-12C", "46", "I2"), + )) + .parse(input) + }, +}; + +/// Macronix MX23L6407 (TSOP-II-44, 3.3V) +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::macronix::MACRONIX_MX23L6407.parse("S024358-M MX23L6407-12C AGB-AXPJ-0 I2 2G447800").is_ok()); +/// assert!(parser::macronix::MACRONIX_MX23L6407.parse("M053257-MG MX23L6407-12C1 AGB-KYGP-0 I2 2M219701A1").is_ok()); +/// ``` +pub static MACRONIX_MX23L6407: NomParser = NomParser { + name: "Macronix MX23L6407", + f: |input| { + alt(( + agb_mx23l("MX23L6407-12C", "58", "I2"), + agb_mx23l("MX23L6407-12C1", "57", "I2"), + )) + .parse(input) + }, +}; + +/// Macronix MX23L12806 (TSOP-II-44, 3.3V) +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::macronix::MACRONIX_MX23L12806.parse("E033938-M MX23L12806-12C AGB-BPPP-0 J2 2F478700").is_ok()); +/// assert!(parser::macronix::MACRONIX_MX23L12806.parse("S052638-MG MX23L12806-12C AGB-BPRS-0 J2 2M396503A1").is_ok()); +/// ``` +pub static MACRONIX_MX23L12806: NomParser = NomParser { + name: "Macronix MX23L12806", + f: |input| agb_mx23l("MX23L12806-12C", "38", "J2").parse(input), +}; + +/// Macronix MX23L12807 (TSOP-II-44, 3.3V) +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::macronix::MACRONIX_MX23L12807.parse("E055058-MG MX23L12807-12C AGB-BPES-0 J2 2N422000A1").is_ok()); +/// assert!(parser::macronix::MACRONIX_MX23L12807.parse("N032358-M MX23L12807-12C AGB-AXVS-0 J2 2H552600").is_ok()); +/// ``` +pub static MACRONIX_MX23L12807: NomParser = NomParser { + name: "Macronix MX23L12807", + f: |input| agb_mx23l("MX23L12807-12C", "58", "J2").parse(input), +}; + +/// Macronix MX23L25607 (TSOP-II-44, 3.3V) +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::macronix::MACRONIX_MX23L25607.parse("M064053-MG MX23L25607-12D2 AGB-BH3E-0 K2 2T151000").is_ok()); +/// ``` +pub static MACRONIX_MX23L25607: NomParser = NomParser { + name: "Macronix MX23L25607", + f: |input| agb_mx23l("MX23L25607-12D2", "53", "K2").parse(input), +}; + +fn dmg_mx23c_old<'a, E: ParseError<&'a str>>( + chip_type: &'static str, + unknown: &'static str, +) -> impl Parser<&'a str, MaskRom, E> { + tuple(( + assembly_vendor_code, + date_code, + tag("-M"), + char(' '), + tag(chip_type), + char(' '), + dmg_rom_code(), + char(' '), + tag(unknown), + char(' '), + lot_code_old, + uppers(1), + )) + .map( + |(_, date_code, _, _, kind, _, rom_id, _, _, _, _, _)| MaskRom { + rom_id: String::from(rom_id), + chip_type: Some(String::from(kind)), + manufacturer: Some(Manufacturer::Macronix), + date_code: Some(date_code), + }, + ) +} + +fn gb_mx23c<'a, E: ParseError<&'a str>>( + chip_type: &'static str, + product_body: &'static str, + unknown: &'static str, +) -> impl Parser<&'a str, MaskRom, E> { + tuple(( + assembly_vendor_code, + date_code, + tag(product_body), + tag("-M"), + opt(tag("G")), // green package? + char(' '), + tag(chip_type), + char(' '), + alt((dmg_rom_code(), cgb_rom_code())), + opt(tuple((char(' '), digits(2)))), + char(' '), + tag(unknown), + char(' '), + lot_code_new, + )) + .map( + |(_, date_code, _, _, _, _, kind, _, rom_id, _, _, _, _, _)| MaskRom { + rom_id: String::from(rom_id), + chip_type: Some(String::from(kind)), + manufacturer: Some(Manufacturer::Macronix), + date_code: Some(date_code), + }, + ) +} + +/// Macronix MX23C4002 (SOP-32, 4.5-5.5V) +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::macronix::MACRONIX_MX23C4002.parse("J9720-M MX23C4002-20 DMG-ATAJ-0 E1 43282F").is_ok()); +/// assert!(parser::macronix::MACRONIX_MX23C4002.parse("C983938-M MX23C4002-20 DMG-AD3E-1 E1 1P0221Y3").is_ok()); +/// ``` +pub static MACRONIX_MX23C4002: NomParser = NomParser { + name: "Macronix MX23C4002", + f: |input| { + alt(( + dmg_mx23c_old("MX23C4002-20", "E1"), + gb_mx23c("MX23C4002-20", "38", "E1"), + )) + .parse(input) + }, +}; + +/// Macronix MX23C8003 (SOP-32, 4.5-5.5V) +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::macronix::MACRONIX_MX23C8003.parse("S010649-M MX23C8003-20 DMG-BMAP-0 F1 1C3876A1").is_ok()); +/// ``` +pub static MACRONIX_MX23C8003: NomParser = NomParser { + name: "Macronix MX23C8003", + f: |input| gb_mx23c("MX23C8003-20", "49", "F1").parse(input), +}; + +/// Macronix MX23C8005 (SOP-32, 4.5-5.5V) +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::macronix::MACRONIX_MX23C8005.parse("C010649-M MX23C8005-12 CGB-BHFE-0 F1 1C5450LB").is_ok()); +/// ``` +pub static MACRONIX_MX23C8005: NomParser = NomParser { + name: "Macronix MX23C8005", + f: |input| gb_mx23c("MX23C8005-12", "49", "F1").parse(input), +}; + +/// Macronix MX23C8006 (TSOP-I-32, 4.5-5.5V) +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::macronix::MACRONIX_MX23C8006.parse("T991349-M MX23C8006-12 DMG-VPHJ-0 F 1A4891A2").is_ok()); +/// ``` +pub static MACRONIX_MX23C8006: NomParser = NomParser { + name: "Macronix MX23C8006", + f: |input| gb_mx23c("MX23C8006-12", "49", "F").parse(input), +}; + +/// Macronix MX23C1603 (TSOP-II-44, 4.5-5.5V) +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::macronix::MACRONIX_MX23C1603.parse("E052804-MG MX23C1603-12A CGB-AAUK-0 G2 1D4499A2A1").is_ok()); +/// assert!(parser::macronix::MACRONIX_MX23C1603.parse("M994395-M MX23C1603-12 1 CGB-VYHE-0 G2 1Q6065A1").is_ok()); +/// ``` +pub static MACRONIX_MX23C1603: NomParser = NomParser { + name: "Macronix MX23C1603", + f: |input| { + alt(( + gb_mx23c("MX23C1603-12 1", "95", "G2"), + gb_mx23c("MX23C1603-12A", "04", "G2"), + gb_mx23c("MX23C1603-12A", "19", "G2"), + )) + .parse(input) + }, +}; + +/// Macronix MX23C3203 (TSOP-II-44, 4.5-5.5V) +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::macronix::MACRONIX_MX23C3203.parse("E034623-M MX23C3203-12A2 CGB-BY3D-0 H2 2G513304").is_ok()); +/// assert!(parser::macronix::MACRONIX_MX23C3203.parse("M004523-M MX23C3203-11A2 CGB-B82J-0 02 H2 2D224301").is_ok()); +/// assert!(parser::macronix::MACRONIX_MX23C3203.parse("M002595-M MX23C3203-12 1 CGB-BY3J-0 H2 1R0833A1").is_ok()); +/// ``` +pub static MACRONIX_MX23C3203: NomParser = NomParser { + name: "Macronix MX23C3203", + f: |input| { + alt(( + gb_mx23c("MX23C3203-12 1", "95", "H2"), + gb_mx23c("MX23C3203-12A2", "95", "H2"), + gb_mx23c("MX23C3203-11A2", "23", "H2"), + gb_mx23c("MX23C3203-12A2", "23", "H2"), + )) + .parse(input) + }, +}; + +fn assembly_vendor_code<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&'a str, char, E> { + satisfy(|c| match c { + 'a' => true, // ChipMOS + 'B' => true, // OSE / Orient Semiconductor Electronics + 'C' => true, // ??? + 'E' => true, // ??? + 'K' => true, // ASEKS + 'J' => true, // ASEJ + 'L' => true, // LINGSEN + 'M' => true, // ??? + 'N' => true, // ??? + 'S' => true, // SPIL + 'T' => true, // STS + 'X' => true, // ASECL + _ => false, + }) + .parse(input) +} + +fn date_code<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&'a str, PartDateCode, E> { + for_nom::year2_week2(input) +} + +fn lot_code_new<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&'a str, &'a str, E> { + recognize(tuple(( + tuple((digits(1), alnum_uppers(1), digits(3), alnum_uppers(1))), + opt(nom::bytes::complete::take(2_usize).and_then(alnum_uppers(2))), + opt(nom::bytes::complete::take(2_usize).and_then(tuple((alnum_uppers(1), digits(1))))), + ))) + .parse(input) +} + +fn lot_code_old<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&'a str, &'a str, E> { + digits(5).parse(input) +} diff --git a/backend/src/parser/mask_rom.rs b/backend/src/parser/mask_rom.rs index e9620447a..f3bf0af06 100644 --- a/backend/src/parser/mask_rom.rs +++ b/backend/src/parser/mask_rom.rs @@ -2,10 +2,10 @@ // // SPDX-License-Identifier: MIT -use super::{week2, year1, year2, LabelParser, Manufacturer, ParsedData, Year}; +use super::{week2, year1, year2, LabelParser, Manufacturer, ParsedData, PartDateCode}; use crate::{ macros::{multi_parser, single_parser}, - time::Week, + parser::{fujitsu::FUJITSU_MASK_ROM, macronix, nec, toshiba}, }; #[derive(Clone, Debug, Eq, PartialEq)] @@ -13,8 +13,7 @@ pub struct MaskRom { pub rom_id: String, pub manufacturer: Option, pub chip_type: Option, - pub year: Option, - pub week: Option, + pub date_code: Option, } impl ParsedData for MaskRom {} @@ -36,8 +35,10 @@ pub fn sharp() -> &'static impl LabelParser { rom_id: c[1].to_owned(), manufacturer: Some(Manufacturer::Sharp), chip_type: Some(map_sharp_mask_rom(&c[3]).unwrap_or(&c[3]).to_owned()), - year: Some(year2(&c[4])?), - week: Some(week2(&c[5])?), + date_code: Some(PartDateCode::YearWeek { + year: year2(&c[4])?, + week: week2(&c[5])?, + }), }) }, ) @@ -58,8 +59,10 @@ pub fn sharp2() -> &'static impl LabelParser { rom_id: c[1].to_owned(), manufacturer: Some(Manufacturer::Sharp), chip_type: None, - year: Some(year2(&c[2])?), - week: Some(week2(&c[3])?), + date_code: Some(PartDateCode::YearWeek { + year: year2(&c[2])?, + week: week2(&c[3])?, + }), }) }, ) @@ -80,79 +83,10 @@ pub fn sharp3() -> &'static impl LabelParser { rom_id: c[1].to_owned(), manufacturer: Some(Manufacturer::Sharp), chip_type: None, - year: Some(year2(&c[2])?), - week: Some(week2(&c[3])?), - }) - }, - ) -} - -/// Macronix MX23C mask ROM chip (1999+) -/// -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::mask_rom::macronix_mx23c_new().parse("M003119-M MX23C1603-12A DMG-VPHP-0 G2 2C882503").is_ok()); -/// assert!(parser::mask_rom::macronix_mx23c_new().parse("E013104-M MX23C1603-12A CGB-BFPU-0 G2 1D2907A1B1").is_ok()); -/// assert!(parser::mask_rom::macronix_mx23c_new().parse("T991349-M MX23C8006-12 DMG-VPHJ-0 F 1A4891A2").is_ok()); -/// assert!(parser::mask_rom::macronix_mx23c_new().parse("M004523-M MX23C3203-11A2 CGB-B82J-0 02 H2 2D224301").is_ok()); -/// ``` -pub fn macronix_mx23c_new() -> &'static impl LabelParser { - single_parser!( - MaskRom, - r#"^[aA-Z]([0-9]{2})([0-9]{2})[0-9]{2}-MG?\ (MX23C[0-9]{4,5}-[0-9]{2}[A-Z]?[0-9]?)\ ([0-9]\ )? ((DMG|CGB)-[[:alnum:]]{3,4}-[0-9])\ ([0-9][0-9]\ )? [A-Z][0-9]?\ [0-9][[:alnum:]]{7,9}$"#, - move |c| { - Ok(MaskRom { - rom_id: c[5].to_owned(), - manufacturer: Some(Manufacturer::Macronix), - chip_type: Some(c[3].to_owned()), - year: Some(year2(&c[1])?), - week: Some(week2(&c[2])?), - }) - }, - ) -} - -/// Macronix MX23C mask ROM chip (pre-1999) -/// -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::mask_rom::macronix_mx23c_old().parse("C9745-M MX23C4002-20 DMG-APOJ-0 E1 43824C").is_ok()); -/// ``` -pub fn macronix_mx23c_old() -> &'static impl LabelParser { - single_parser!( - MaskRom, - r#"^[A-Z]([0-9]{2})([0-9]{2})-M\ (MX23C[0-9]{4}-[0-9]{2}[A-Z]?[0-9]?)\ ((DMG|CGB)-[[:alnum:]]{3,4}-[0-9])\ [A-Z][0-9]?\ [[:alnum:]]{6}$"#, - move |c| { - Ok(MaskRom { - rom_id: c[4].to_owned(), - manufacturer: Some(Manufacturer::Macronix), - chip_type: Some(c[3].to_owned()), - year: Some(year2(&c[1])?), - week: Some(week2(&c[2])?), - }) - }, - ) -} - -/// Macronix MX23L mask ROM chip -/// -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::mask_rom::macronix_mx23l().parse("S013607-M MX23L6406-12B AGB-AWAP-0 I2 2E489301").is_ok()); -/// assert!(parser::mask_rom::macronix_mx23l().parse("B063953-MG MX23L25607-12D2 AGB-B24P-0 K2 2T016800").is_ok()); -/// assert!(parser::mask_rom::macronix_mx23l().parse("a064553-MG MX23L25607-12D2 AGB-B24E-0 K2 2T536900").is_ok()); -/// ``` -pub fn macronix_mx23l() -> &'static impl LabelParser { - single_parser!( - MaskRom, - r#"^[aA-Z]([0-9]{2})([0-9]{2})[0-9]{2}-MG?\ (MX23L[0-9]{4,5}-[0-9]{2}[A-Z]?[0-9]?)\ ([0-9]\ )? (AGB-[[:alnum:]]{3,4}-[0-9])\ ([0-9][0-9]\ )? [A-Z][0-9]?\ [[:alnum:]]{8,10}$"#, - move |c| { - Ok(MaskRom { - rom_id: c[5].to_owned(), - manufacturer: Some(Manufacturer::Macronix), - chip_type: Some(c[3].to_owned()), - year: Some(year2(&c[1])?), - week: Some(week2(&c[2])?), + date_code: Some(PartDateCode::YearWeek { + year: year2(&c[2])?, + week: week2(&c[3])?, + }), }) }, ) @@ -173,8 +107,7 @@ pub fn oki_old() -> &'static impl LabelParser { rom_id: c[1].to_owned(), manufacturer: Some(Manufacturer::Oki), chip_type: None, - year: None, - week: None, + date_code: None, }) }, ) @@ -196,8 +129,10 @@ pub fn oki_msm53x011e() -> &'static impl LabelParser { rom_id: c[1].to_owned(), manufacturer: Some(Manufacturer::Oki), chip_type: Some(format!("MS{}", &c[3])), - year: Some(year1(&c[4])?), - week: Some(week2(&c[5])?), + date_code: Some(PartDateCode::YearWeek { + year: year1(&c[4])?, + week: week2(&c[5])?, + }), }) }, ) @@ -218,118 +153,10 @@ pub fn oki_mr531614g() -> &'static impl LabelParser { rom_id: c[1].to_owned(), manufacturer: Some(Manufacturer::Oki), chip_type: Some(format!("M{}", &c[3])), - year: Some(year1(&c[4])?), - week: Some(week2(&c[5])?), - }) - }, - ) -} - -/// NEC mask ROM -/// -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::mask_rom::nec().parse("NEC JAPAN DMG-SAJ-0 C1 UPD23C1001EGW-J01 9010E9702").is_ok()); -/// ``` -pub fn nec() -> &'static impl LabelParser { - single_parser!( - MaskRom, - r#"^NEC\ JAPAN\ ((DMG|CGB)-[[:alnum:]]{3,4}-[0-9])\ [A-Z][0-9]\ (UPD23C[0-9]{4}[[:alnum:]]{3,4})-[A-Z][0-9]{2}\ ([0-9]{2})([0-9]{2})[A-Z][0-9]{4}$"#, - move |c| { - Ok(MaskRom { - rom_id: c[1].to_owned(), - manufacturer: Some(Manufacturer::Nec), - chip_type: Some(c[3].to_owned()), - year: Some(year2(&c[4])?), - week: Some(week2(&c[5])?), - }) - }, - ) -} - -/// Unknown mask ROM with NEC-like labeling -/// -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::mask_rom::nec_like().parse("DMG-ZLE-0 E1 N-4001EAGW-J14 9329X7007").is_ok()); -/// ``` -pub fn nec_like() -> &'static impl LabelParser { - single_parser!( - MaskRom, - r#"^((DMG|CGB)-[[:alnum:]]{3,4}-[0-9])\ [A-Z][0-9]\ (N-[0-9]{4}[[:alnum:]]{3,4})-[A-Z][0-9]{2}\ ([0-9]{2})([0-9]{2})[A-Z][0-9]{4}$"#, - move |c| { - Ok(MaskRom { - rom_id: c[1].to_owned(), - manufacturer: None, - chip_type: Some(c[3].to_owned()), - year: Some(year2(&c[4])?), - week: Some(week2(&c[5])?), - }) - }, - ) -} - -/// AT&T mask ROM -/// -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::mask_rom::at_t().parse("Ⓜ AT&T JAPAN DMG-Q6E-0 C1 23C1001EAGW-K37 9351E9005").is_ok()); -/// ``` -pub fn at_t() -> &'static impl LabelParser { - single_parser!( - MaskRom, - r#"^Ⓜ\ AT&T\ JAPAN\ ((DMG|CGB)-[[:alnum:]]{3,4}-[0-9])\ [A-Z][0-9]\ (23C[0-9]{4}[[:alnum:]]{3,4})-[A-Z][0-9]{2}\ ([0-9]{2})([0-9]{2})[A-Z][0-9]{4}$"#, - move |c| { - Ok(MaskRom { - rom_id: c[1].to_owned(), - manufacturer: Some(Manufacturer::AtT), - chip_type: Some(c[3].to_owned()), - year: Some(year2(&c[4])?), - week: Some(week2(&c[5])?), - }) - }, - ) -} - -/// Standard Microsystems mask ROM -/// -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::mask_rom::smsc().parse("STANDARD MICRO DMG-BIA-0 C1 23C1001EGW-J61 9140E9017").is_ok()); -/// ``` -pub fn smsc() -> &'static impl LabelParser { - single_parser!( - MaskRom, - r#"^STANDARD\ MICRO\ ((DMG|CGB)-[[:alnum:]]{3,4}-[0-9])\ [A-Z][0-9]\ (23C[0-9]{4}[[:alnum:]]{3,4})-[A-Z][0-9]{2}\ ([0-9]{2})([0-9]{2})[A-Z][0-9]{4}$"#, - move |c| { - Ok(MaskRom { - rom_id: c[1].to_owned(), - manufacturer: Some(Manufacturer::Smsc), - chip_type: Some(c[3].to_owned()), - year: Some(year2(&c[4])?), - week: Some(week2(&c[5])?), - }) - }, - ) -} - -/// MANI mask ROM -/// -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::mask_rom::mani().parse("MANI DMG-MQE-2 23C4001EAGW-J22 9447X9200").is_ok()); -/// ``` -pub fn mani() -> &'static impl LabelParser { - single_parser!( - MaskRom, - r#"^MANI\ ((DMG|CGB)-[[:alnum:]]{3,4}-[0-9])\ (23C[0-9]{4}[[:alnum:]]{3,4})-[A-Z][0-9]{2}\ ([0-9]{2})([0-9]{2})[A-Z][0-9]{4}$"#, - move |c| { - Ok(MaskRom { - rom_id: c[1].to_owned(), - manufacturer: Some(Manufacturer::Mani), - chip_type: Some(c[3].to_owned()), - year: Some(year2(&c[4])?), - week: Some(week2(&c[5])?), + date_code: Some(PartDateCode::YearWeek { + year: year1(&c[4])?, + week: week2(&c[5])?, + }), }) }, ) @@ -352,30 +179,10 @@ pub fn sharp_glop_top_28() -> &'static impl LabelParser { rom_id: c[2].to_owned(), manufacturer: None, chip_type: Some(c[1].to_owned()), - year: Some(year2(&c[3])?), - week: Some(week2(&c[4])?), - }) - }, - ) -} - -/// Toshiba mask ROM -/// -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::mask_rom::toshiba().parse("TOSHIBA 9136EAI TC531001CF DMG-NCE-0 C1 J541 JAPAN").is_ok()); -/// ``` -pub fn toshiba() -> &'static impl LabelParser { - single_parser!( - MaskRom, - r#"^TOSHIBA\ ([0-9]{2})([0-9]{2})EAI\ (TC53[0-9]{4}[A-Z]{2})\ ((DMG|CGB)-[[:alnum:]]{3,4}-[0-9])\ [A-Z][0-9]\ [A-Z][0-9]{3}\ JAPAN$"#, - move |c| { - Ok(MaskRom { - rom_id: c[4].to_owned(), - manufacturer: Some(Manufacturer::Toshiba), - chip_type: (Some(c[3].to_owned())), - year: Some(year2(&c[1])?), - week: Some(week2(&c[2])?), + date_code: Some(PartDateCode::YearWeek { + year: year2(&c[3])?, + week: week2(&c[4])?, + }), }) }, ) @@ -396,8 +203,7 @@ pub fn samsung() -> &'static impl LabelParser { rom_id: c[2].to_owned(), manufacturer: Some(Manufacturer::Samsung), chip_type: (Some(c[1].to_owned())), - year: None, - week: None, + date_code: None, }) }, ) @@ -418,31 +224,7 @@ pub fn samsung2() -> &'static impl LabelParser { rom_id: c[2].to_owned(), manufacturer: Some(Manufacturer::Samsung), chip_type: (Some(c[1].to_owned())), - year: None, - week: None, - }) - }, - ) -} - -/// Fujitsu Mask ROM -/// -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::mask_rom::fujitsu().parse("JAPAN DMG-GKX-0 D1 1P0 AK 9328 R09").is_ok()); -/// assert!(parser::mask_rom::fujitsu().parse("JAPAN DMG-WJA-0 E1 3NH AK 9401 R17").is_ok()); -/// ``` -pub fn fujitsu() -> &'static impl LabelParser { - single_parser!( - MaskRom, - r#"^JAPAN\ ((DMG|CGB)-[[:alnum:]]{3,4}-[0-9])\ [A-Z][0-9]\ [0-9][A-Z][[:alnum:]]\ [A-Z]{2}\ ([0-9]{2})([0-9]{2})\ [A-Z][0-9]{2}$"#, - move |c| { - Ok(MaskRom { - rom_id: c[1].to_owned(), - manufacturer: Some(Manufacturer::Fujitsu), - chip_type: None, - year: Some(year2(&c[3])?), - week: Some(week2(&c[4])?), + date_code: None, }) }, ) @@ -466,8 +248,10 @@ pub fn oki_mr26v() -> &'static impl LabelParser { rom_id: c[1].to_owned(), manufacturer: Some(Manufacturer::Oki), chip_type: Some(format!("M{}", &c[2])), - year: Some(year1(&c[3])?), - week: Some(week2(&c[4])?), + date_code: Some(PartDateCode::YearWeek { + year: year1(&c[3])?, + week: week2(&c[4])?, + }), }) }, ) @@ -490,8 +274,9 @@ pub fn oki_mr27v() -> &'static impl LabelParser { rom_id: c[1].to_owned(), manufacturer: Some(Manufacturer::Oki), chip_type: Some(format!("M{}", &c[2])), - year: Some(year1(&c[3])?), - week: None, + date_code: Some(PartDateCode::Year { + year: year1(&c[3])?, + }), }) }, ) @@ -512,8 +297,10 @@ pub fn magnachip_ac23v() -> &'static impl LabelParser { rom_id: c["rom_id"].to_owned(), manufacturer: Some(Manufacturer::Magnachip), chip_type: Some(c["kind"].to_owned()), - year: Some(year2(&c["year"])?), - week: Some(week2(&c["week"])?), + date_code: Some(PartDateCode::YearWeek { + year: year2(&c["year"])?, + week: week2(&c["week"])?, + }), }) }, ) @@ -535,8 +322,7 @@ pub fn hynix_ac23v() -> &'static impl LabelParser { rom_id: c[2].to_owned(), manufacturer: Some(Manufacturer::Hynix), chip_type: Some(c[1].to_owned()), - year: None, - week: None, + date_code: None, }) }, ) @@ -572,6 +358,8 @@ fn map_sharp_mask_rom(code: &str) -> Option<&'static str> { // Unknown 16 Mb // maybe: LH5316400 / LH5316500 series / LH5316P00 series "LH537M" => None, + // Unknown 32 Mb + "LHMN5M" => None, _ => None, } } @@ -581,7 +369,12 @@ pub fn agb_mask_rom_tsop_ii_44() -> &'static impl LabelParser { MaskRom, magnachip_ac23v(), hynix_ac23v(), - macronix_mx23l(), + ¯onix::MACRONIX_MX23L3206, + ¯onix::MACRONIX_MX23L6406, + ¯onix::MACRONIX_MX23L6407, + ¯onix::MACRONIX_MX23L12806, + ¯onix::MACRONIX_MX23L12807, + ¯onix::MACRONIX_MX23L25607, oki_mr26v(), oki_mr27v(), ) @@ -597,19 +390,24 @@ pub fn mask_rom_sop_32() -> &'static impl LabelParser { sharp(), sharp2(), sharp3(), - macronix_mx23c_new(), - macronix_mx23c_old(), + ¯onix::MACRONIX_MX23C4002, + ¯onix::MACRONIX_MX23C8003, + ¯onix::MACRONIX_MX23C8005, oki_msm53x011e(), oki_mr531614g(), - nec(), - nec_like(), - at_t(), - smsc(), - mani(), - toshiba(), + &nec::NEC_UPD23C1001E, + &nec::NEC_UPD23C2001E, + &nec::NEC_UPD23C4001E, + &nec::NEC_UPD23C8001E, + &nec::AT_T_UPD23C1001E, + &nec::SMSC_UPD23C1001E, + &nec::MANI_UPD23C4001E, + &toshiba::TOSHIBA_TC531001, + &toshiba::TOSHIBA_TC532000, + &toshiba::TOSHIBA_TC534000, samsung(), samsung2(), - fujitsu(), + &FUJITSU_MASK_ROM, oki_old(), ) } @@ -618,40 +416,28 @@ pub fn mask_rom_tsop_i_32() -> &'static impl LabelParser { multi_parser!( MaskRom, sharp(), - macronix_mx23c_new(), + ¯onix::MACRONIX_MX23C8006, oki_msm53x011e(), oki_mr531614g(), - nec(), - nec_like(), - at_t(), - smsc(), - mani(), - toshiba(), samsung(), samsung2(), - fujitsu(), oki_old(), ) } -pub fn mask_rom_tsop_ii_44() -> &'static impl LabelParser { +pub fn mask_rom_tsop_ii_44_5v() -> &'static impl LabelParser { multi_parser!( MaskRom, sharp(), sharp2(), sharp3(), - macronix_mx23c_new(), + ¯onix::MACRONIX_MX23C1603, + ¯onix::MACRONIX_MX23C3203, oki_msm53x011e(), oki_mr531614g(), - nec(), - nec_like(), - at_t(), - smsc(), - mani(), - toshiba(), + &nec::NEC_UPD23C16019W, samsung(), samsung2(), - fujitsu(), oki_old(), ) } @@ -664,15 +450,8 @@ pub fn mask_rom_qfp_44() -> &'static impl LabelParser { sharp3(), oki_msm53x011e(), oki_mr531614g(), - nec(), - nec_like(), - at_t(), - smsc(), - mani(), - toshiba(), samsung(), samsung2(), - fujitsu(), oki_old(), ) } diff --git a/backend/src/parser/mgb_amp.rs b/backend/src/parser/mgb_amp.rs deleted file mode 100644 index ace522fe4..000000000 --- a/backend/src/parser/mgb_amp.rs +++ /dev/null @@ -1,50 +0,0 @@ -// SPDX-FileCopyrightText: 2017-2023 Joonas Javanainen -// -// SPDX-License-Identifier: MIT - -use super::{week2, year2, ChipYearWeek, LabelParser, Manufacturer}; -use crate::macros::{multi_parser, single_parser}; - -pub type MgbAmp = ChipYearWeek; - -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::mgb_amp::sharp_ir3r53n().parse("AMP MGB IR3R53N 9806 a").is_ok()); -/// ``` -pub fn sharp_ir3r53n() -> &'static impl LabelParser { - single_parser!( - MgbAmp, - r#"^AMP\ MGB\ IR3R53N\ ([0-9]{2})([0-9]{2})\ [a-zA-Z]$"#, - move |c| { - Ok(MgbAmp { - kind: "IR3R53N".to_owned(), - manufacturer: Some(Manufacturer::Sharp), - year: Some(year2(&c[1])?), - week: Some(week2(&c[2])?), - }) - }, - ) -} - -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::mgb_amp::sharp_ir3r56n().parse("AMP MGB IR3R56N 0040 C").is_ok()); -/// ``` -pub fn sharp_ir3r56n() -> &'static impl LabelParser { - single_parser!( - MgbAmp, - r#"^AMP\ MGB\ IR3R56N\ ([0-9]{2})([0-9]{2})\ [a-zA-Z]$"#, - move |c| { - Ok(MgbAmp { - kind: "IR3R56N".to_owned(), - manufacturer: Some(Manufacturer::Sharp), - year: Some(year2(&c[1])?), - week: Some(week2(&c[2])?), - }) - }, - ) -} - -pub fn mgb_amp() -> &'static impl LabelParser { - multi_parser!(MgbAmp, sharp_ir3r53n(), sharp_ir3r56n()) -} diff --git a/backend/src/parser/mgl_transformer.rs b/backend/src/parser/mgl_transformer.rs deleted file mode 100644 index d62b7216f..000000000 --- a/backend/src/parser/mgl_transformer.rs +++ /dev/null @@ -1,32 +0,0 @@ -// SPDX-FileCopyrightText: 2017-2023 Joonas Javanainen -// -// SPDX-License-Identifier: MIT - -use super::{LabelParser, Manufacturer, ParsedData}; -use crate::macros::single_parser; - -#[derive(Clone, Debug, Eq, PartialEq)] -pub struct Transformer { - pub kind: String, - pub manufacturer: Option, -} - -impl ParsedData for Transformer {} - -/// ``` -/// # use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::mgl_transformer::mitsumi_unknown().parse("82Y7").is_ok()); -/// assert!(parser::mgl_transformer::mitsumi_unknown().parse("84Z7").is_ok()); -/// ``` -pub fn mitsumi_unknown() -> &'static impl LabelParser { - single_parser!(Transformer, r#"^(82Y7|84Z7)$"#, move |c| { - Ok(Transformer { - kind: c[1].to_owned(), - manufacturer: Some(Manufacturer::Mitsumi), - }) - }) -} - -pub fn mgl_transformer() -> &'static impl LabelParser { - mitsumi_unknown() -} diff --git a/backend/src/parser/mitsubishi.rs b/backend/src/parser/mitsubishi.rs new file mode 100644 index 000000000..b8c912e79 --- /dev/null +++ b/backend/src/parser/mitsubishi.rs @@ -0,0 +1,30 @@ +// SPDX-FileCopyrightText: Joonas Javanainen +// +// SPDX-License-Identifier: MIT + +use nom::{bytes::streaming::tag, sequence::tuple, Parser as _}; + +use super::{ + for_nom::{alnum_uppers, digits, year1}, + GenericPart, Manufacturer, NomParser, +}; +use crate::parser::PartDateCode; + +/// Mitsubishi M62021P +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::mitsubishi::MITSUBISHI_M62021P.parse("2021 7Z2").is_ok()); +/// ``` +pub static MITSUBISHI_M62021P: NomParser = NomParser { + name: "Mitsubishi M62021P", + f: |input| { + tuple((tag("2021 "), tuple((year1, alnum_uppers(1), digits(1))))) + .map(|(_, (year, _, _))| GenericPart { + kind: "M62021P".to_owned(), + manufacturer: Some(Manufacturer::Mitsubishi), + date_code: Some(PartDateCode::Year { year }), + }) + .parse(input) + }, +}; diff --git a/backend/src/parser/mitsumi.rs b/backend/src/parser/mitsumi.rs new file mode 100644 index 000000000..8e1932fb7 --- /dev/null +++ b/backend/src/parser/mitsumi.rs @@ -0,0 +1,155 @@ +// SPDX-FileCopyrightText: Joonas Javanainen +// +// SPDX-License-Identifier: MIT + +use nom::{ + branch::alt, bytes::streaming::tag, character::streaming::char, combinator::opt, + sequence::tuple, Parser as _, +}; + +use super::{ + for_nom::{alnum_uppers, uppers, year1, year1_week2}, + GenericPart, Manufacturer, NomParser, +}; +use crate::parser::PartDateCode; + +/// Mitsumi MM1026A +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::mitsumi::MITSUMI_MM1026A.parse("843 26A").is_ok()); +/// assert!(parser::mitsumi::MITSUMI_MM1026A.parse("1L51 26A").is_ok()); +/// ``` +pub static MITSUMI_MM1026A: NomParser = NomParser { + name: "Mitsumi MM1026A", + f: |input| { + tuple((year1, alt((alnum_uppers(3), alnum_uppers(2))), tag(" 26A"))) + .map(|(year, _, _)| GenericPart { + kind: "MM1026A".to_owned(), + manufacturer: Some(Manufacturer::Mitsumi), + date_code: Some(PartDateCode::Year { year }), + }) + .parse(input) + }, +}; + +/// Mitsumi MM1134A +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::mitsumi::MITSUMI_MM1134A.parse("939 134A").is_ok()); +/// ``` +pub static MITSUMI_MM1134A: NomParser = NomParser { + name: "Mitsumi MM1134A", + f: |input| { + tuple((year1_week2, tag(" 134A"))) + .map(|(date_code, _)| GenericPart { + kind: "MM1134A".to_owned(), + manufacturer: Some(Manufacturer::Mitsumi), + date_code: Some(date_code), + }) + .parse(input) + }, +}; + +/// Mitsumi MM1514X +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::mitsumi::MITSUMI_MM1514X.parse("105 514X").is_ok()); +/// assert!(parser::mitsumi::MITSUMI_MM1514X.parse("081 514X").is_ok()); +/// ``` +pub static MITSUMI_MM1514X: NomParser = NomParser { + name: "Mitsumi MM1514X", + f: |input| { + tuple((year1, alnum_uppers(2), tag(" 514X"))) + .map(|(year, _, _)| GenericPart { + kind: "MM1514X".to_owned(), + manufacturer: Some(Manufacturer::Mitsumi), + date_code: Some(PartDateCode::Year { year }), + }) + .parse(input) + }, +}; + +/// Mitsumi MM1581A +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::mitsumi::MITSUMI_MM1581A.parse("422 1581A").is_ok()); +/// ``` +pub static MITSUMI_MM1581A: NomParser = NomParser { + name: "Mitsumi MM1581A", + f: |input| { + tuple((year1_week2, tag(" 1581A"))) + .map(|(date_code, _)| GenericPart { + kind: "MM1581A".to_owned(), + manufacturer: Some(Manufacturer::Mitsumi), + date_code: Some(date_code), + }) + .parse(input) + }, +}; + +/// Mitsumi MM1592F +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::mitsumi::MITSUMI_MM1592F.parse("548 592F").is_ok()); +/// ``` +pub static MITSUMI_MM1592F: NomParser = NomParser { + name: "Mitsumi MM1592F", + f: |input| { + tuple((year1_week2, tag(" 592F"))) + .map(|(date_code, _)| GenericPart { + kind: "MM1592F".to_owned(), + manufacturer: Some(Manufacturer::Mitsumi), + date_code: Some(date_code), + }) + .parse(input) + }, +}; + +/// Mitsumi PM +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::mitsumi::MITSUMI_PM.parse("MITSUMI JAPAN 528A PM C").is_ok()); +/// ``` +pub static MITSUMI_PM: NomParser = NomParser { + name: "Mitsumi PM", + f: |input| { + tuple(( + tag("MITSUMI JAPAN "), + year1_week2, + opt(char(' ')), + uppers(1), + char(' '), + alt((tag("PM B3"), tag("PM B4"), tag("PM C"))), + )) + .map(|(_, date_code, _, _, _, kind)| GenericPart { + kind: String::from(kind), + manufacturer: Some(Manufacturer::Mitsumi), + date_code: Some(date_code), + }) + .parse(input) + }, +}; + +/// ``` +/// # use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::mitsumi::MITSUMI_MGL_TRANSFORMER.parse("82Y7").is_ok()); +/// assert!(parser::mitsumi::MITSUMI_MGL_TRANSFORMER.parse("84Z7").is_ok()); +/// ``` +pub static MITSUMI_MGL_TRANSFORMER: NomParser = NomParser { + name: "Mitsumi MGL transformer", + f: |input| { + alt((tag("82Y7"), tag("84Z7"))) + .map(|kind| GenericPart { + kind: String::from(kind), + manufacturer: Some(Manufacturer::Mitsumi), + date_code: None, + }) + .parse(input) + }, +}; diff --git a/backend/src/parser/nec.rs b/backend/src/parser/nec.rs new file mode 100644 index 000000000..d7f25a5e8 --- /dev/null +++ b/backend/src/parser/nec.rs @@ -0,0 +1,335 @@ +// SPDX-FileCopyrightText: Joonas Javanainen +// +// SPDX-License-Identifier: MIT + +use nom::{ + branch::alt, + bytes::streaming::tag, + character::streaming::char, + combinator::{cond, recognize, value}, + error::ParseError, + sequence::tuple, + Parser, +}; + +use super::{ + for_nom::{cgb_rom_code, digits, dmg_rom_code, uppers}, + GenericPart, MaskRom, +}; +use crate::parser::{for_nom::year2_week2, Manufacturer, NomParser}; + +/// NEC μPD442012A-X (TSOP-I-48) +/// +/// Source: +/// "NEC data sheet - MOS integrated circuit μPD442012A-X - 2M-bit CMOS static RAM 128k-word by 16-bit extended temperature operation" +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::nec::NEC_UPD442012A_X.parse("NEC JAPAN D442012AGY-BB85X-MJH 0037K7027").is_ok()); +/// assert!(parser::nec::NEC_UPD442012A_X.parse("NEC JAPAN D442012AGY-BC85X-MJH 0330K7043").is_ok()); +/// ``` +pub static NEC_UPD442012A_X: NomParser = NomParser { + name: "NEC μPD442012A-X", + f: |input| { + tuple(( + tag("NEC JAPAN "), + recognize(tuple(( + tag("D442012A"), + tag("GY"), // package + char('-'), + alt((tag("BB"), tag("BC"))), // voltage + tag("85"), // speed + char('X'), // temperature + char('-'), + tag("MJH"), + ))), + char(' '), + tuple((year2_week2, uppers(1), digits(4))), + )) + .map(|(_, kind, _, (date_code, _, _))| GenericPart { + kind: String::from(kind), + manufacturer: Some(Manufacturer::Nec), + date_code: Some(date_code), + }) + .parse(input) + }, +}; + +/// NEC μPD442012L-X (TSOP-I-48) +/// +/// Source: +/// "NEC data sheet - MOS integrated circuit μPD442012L-X - 2M-bit CMOS static RAM 128k-word by 16-bit extended temperature operation" +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::nec::NEC_UPD442012L_X.parse("NEC JAPAN D442012LGY-B85X-MJH 0138K7037").is_ok()); +/// ``` +pub static NEC_UPD442012L_X: NomParser = NomParser { + name: "NEC μPD442012L-X", + f: |input| { + tuple(( + tag("NEC JAPAN "), + recognize(tuple(( + tag("D442012L"), + tag("GY"), // package + char('-'), + alt((tag("B"), tag("C"))), // voltage + tag("85"), // speed + char('X'), // temperature + char('-'), + tag("MJH"), + ))), + char(' '), + tuple((year2_week2, uppers(1), digits(4))), + )) + .map(|(_, kind, _, (date_code, _, _))| GenericPart { + kind: String::from(kind), + manufacturer: Some(Manufacturer::Nec), + date_code: Some(date_code), + }) + .parse(input) + }, +}; + +fn upd23c<'a, E: ParseError<&'a str>>( + chip_type: &'static str, + package: Package, +) -> impl Parser<&'a str, MaskRom, E> { + tuple(( + alt((dmg_rom_code(), cgb_rom_code())), + char(' '), + uppers(1).and(digits(1)), + char(' '), + tuple(( + value("μPD23C", tag("N-")), + tag(chip_type), + tag(package.code()), + )) + .and(char('-').and(uppers(1)).and(digits(2))), + char(' '), + tuple((year2_week2, uppers(1), digits(4))), + )) + .map( + |(rom_id, _, _, _, ((series, kind, package), _), _, (date_code, _, _))| MaskRom { + rom_id: String::from(rom_id), + manufacturer: Some(Manufacturer::Nec), + chip_type: Some(format!("{series}{kind}{package}")), + date_code: Some(date_code), + }, + ) +} + +fn upd23c_old<'a, E: ParseError<&'a str>>( + chip_type: &'static str, + package: Package, +) -> impl Parser<&'a str, MaskRom, E> { + tuple(( + tag("NEC JAPAN "), + alt((dmg_rom_code(), cgb_rom_code())), + char(' '), + uppers(1).and(digits(1)), + char(' '), + tuple(( + value("μPD23C", tag("UPD23C")), + tag(chip_type), + tag(package.code()), + )) + .and(char('-').and(uppers(1)).and(digits(2))), + char(' '), + tuple((year2_week2, uppers(1), digits(4))), + )) + .map( + |(_, rom_id, _, _, _, ((series, kind, package), _), _, (date_code, _, _))| MaskRom { + rom_id: String::from(rom_id), + manufacturer: Some(Manufacturer::Nec), + chip_type: Some(format!("{series}{kind}{package}")), + date_code: Some(date_code), + }, + ) +} + +fn upd23c_licensed<'a, E: ParseError<&'a str>>( + chip_type: &'static str, + package: Package, + (manufacturer_text, manufacturer): (&'static str, Manufacturer), + long: bool, +) -> impl Parser<&'a str, MaskRom, E> { + tuple(( + tag(manufacturer_text), + char(' '), + alt((dmg_rom_code(), cgb_rom_code())), + cond(long, tuple((char(' '), uppers(1).and(digits(1))))), + char(' '), + tuple(( + value("μPD23C", tag("23C")), + tag(chip_type), + tag(package.code()), + )) + .and(char('-').and(uppers(1)).and(digits(2))), + char(' '), + tuple((year2_week2, uppers(1), digits(4))), + )) + .map( + move |(_, _, rom_id, _, _, ((series, kind, package), _), _, (date_code, _, _))| MaskRom { + rom_id: String::from(rom_id), + manufacturer: Some(manufacturer), + chip_type: Some(format!("{series}{kind}{package}")), + date_code: Some(date_code), + }, + ) +} + +/// NEC μPD23C1001E (SOP-32, 5V) +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::nec::NEC_UPD23C1001E.parse("NEC JAPAN DMG-SAJ-0 C1 UPD23C1001EGW-J01 9010E9702").is_ok()); +/// assert!(parser::nec::NEC_UPD23C1001E.parse("DMG-HQE-0 C1 N-1001EGW-J23 9110E9001").is_ok()); +/// ``` +pub static NEC_UPD23C1001E: NomParser = NomParser { + name: "NEC μPD23C1001E", + f: |input| { + let package = Package::Sop32; + alt(( + upd23c_old("1001E", package), + upd23c("1001E", package), + upd23c("1001EA", package), + upd23c("1001EU", package), + )) + .parse(input) + }, +}; + +/// NEC μPD23C2001E (SOP-32, 5V) +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::nec::NEC_UPD23C2001E.parse("DMG-AVLP-0 D1 N-2001EUGW-J38 9840E7004").is_ok()); +/// ``` +pub static NEC_UPD23C2001E: NomParser = NomParser { + name: "NEC μPD23C2001E", + f: |input| { + let package = Package::Sop32; + alt((upd23c("2001E", package), upd23c("2001EU", package))).parse(input) + }, +}; + +/// NEC μPD23C4001E (SOP-32, 5V) +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::nec::NEC_UPD23C4001E.parse("DMG-AYWJ-1 E1 N-4001EJGW-J82 9804E7012").is_ok()); +/// assert!(parser::nec::NEC_UPD23C4001E.parse("DMG-ZLE-0 E1 N-4001EAGW-J14 9325X9700").is_ok()); +/// ``` +pub static NEC_UPD23C4001E: NomParser = NomParser { + name: "NEC μPD23C4001E", + f: |input| { + let package = Package::Sop32; + alt(( + upd23c("4001EA", package), + upd23c("4001EJ", package), + upd23c("4001EU", package), + )) + .parse(input) + }, +}; + +/// NEC μPD23C8001E (SOP-32, 5V) +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::nec::NEC_UPD23C8001E.parse("DMG-AGQE-0 F1 N-8001EJGW-K14 0033K7036").is_ok()); +/// ``` +pub static NEC_UPD23C8001E: NomParser = NomParser { + name: "NEC μPD23C8001E", + f: |input| upd23c("8001EJ", Package::Sop32).parse(input), +}; + +/// NEC μPD23C16019W (TSOP-II-44, 5V) +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::nec::NEC_UPD23C16019W.parse("DMG-VPHP-0 G2 N-16019WG5-M51 0029K7039").is_ok()); +/// ``` +pub static NEC_UPD23C16019W: NomParser = NomParser { + name: "NEC μPD23C16019W", + f: |input| upd23c("16019W", Package::TsopIi44).parse(input), +}; + +/// AT&T μPD23C1001E (SOP-32, 5V) +/// +/// Original by NEC, manufactured under license (?) +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::nec::AT_T_UPD23C1001E.parse("Ⓜ AT&T JAPAN DMG-Q6E-0 C1 23C1001EAGW-K37 9351E9005").is_ok()); +/// ``` +pub static AT_T_UPD23C1001E: NomParser = NomParser { + name: "AT&T μPD23C1001E", + f: |input| { + upd23c_licensed( + "1001EA", + Package::Sop32, + ("Ⓜ AT&T JAPAN", Manufacturer::AtT), + true, + ) + .parse(input) + }, +}; + +/// Standard Microsystems μPD23C1001E (SOP-32, 5V) +/// +/// Original by NEC, manufactured under license (?) +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::nec::SMSC_UPD23C1001E.parse("STANDARD MICRO DMG-BIA-0 C1 23C1001EGW-J61 9140E9017").is_ok()); +/// ``` +pub static SMSC_UPD23C1001E: NomParser = NomParser { + name: "SMSC μPD23C1001E", + f: |input| { + let package = Package::Sop32; + let manufacturer = ("STANDARD MICRO", Manufacturer::Smsc); + alt(( + upd23c_licensed("1001E", package, manufacturer, true), + upd23c_licensed("1001EA", package, manufacturer, true), + )) + .parse(input) + }, +}; + +/// MANI μPD23C4001E (SOP-32, 5V) +/// +/// Original by NEC, manufactured under license (?) +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::nec::MANI_UPD23C4001E.parse("MANI DMG-MQE-2 23C4001EAGW-J22 9447X9200").is_ok()); +/// ``` +pub static MANI_UPD23C4001E: NomParser = NomParser { + name: "MANI μPD23C4001E", + f: |input| { + upd23c_licensed( + "4001EA", + Package::Sop32, + ("MANI", Manufacturer::Mani), + false, + ) + .parse(input) + }, +}; + +#[derive(Copy, Clone, Debug, PartialEq, Eq)] +enum Package { + Sop32, + TsopIi44, +} + +impl Package { + pub const fn code(&self) -> &'static str { + match self { + Package::Sop32 => "GW", + Package::TsopIi44 => "G5", + } + } +} diff --git a/backend/src/parser/oxy_pmic.rs b/backend/src/parser/oxy_pmic.rs deleted file mode 100644 index e9327efad..000000000 --- a/backend/src/parser/oxy_pmic.rs +++ /dev/null @@ -1,31 +0,0 @@ -// SPDX-FileCopyrightText: 2017-2023 Joonas Javanainen -// -// SPDX-License-Identifier: MIT - -use super::{week2, year1, ChipYearWeek, LabelParser, Manufacturer}; -use crate::macros::single_parser; - -pub type OxyPmic = ChipYearWeek; - -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::oxy_pmic::mitsumi_pm_c().parse("MITSUMI JAPAN 528A PM C").is_ok()); -/// ``` -pub fn mitsumi_pm_c() -> &'static impl LabelParser { - single_parser!( - OxyPmic, - r#"^MITSUMI\ JAPAN\ ([0-9])([0-9]{2})\ ?[A-Z]\ PM\ C$"#, - move |c| { - Ok(OxyPmic { - kind: "PM C".to_owned(), - manufacturer: Some(Manufacturer::Mitsumi), - year: Some(year1(&c[1])?), - week: Some(week2(&c[2])?), - }) - }, - ) -} - -pub fn oxy_pmic() -> &'static impl LabelParser { - mitsumi_pm_c() -} diff --git a/backend/src/parser/oxy_u4.rs b/backend/src/parser/oxy_u4.rs index f9ad18337..a36bdd4b5 100644 --- a/backend/src/parser/oxy_u4.rs +++ b/backend/src/parser/oxy_u4.rs @@ -2,26 +2,26 @@ // // SPDX-License-Identifier: MIT -use super::{week2, year1, ChipYearWeek, LabelParser}; -use crate::macros::single_parser; - -pub type OxyU4 = ChipYearWeek; +use super::{week2, year1, GenericPart, LabelParser}; +use crate::{macros::single_parser, parser::PartDateCode}; /// ``` /// use gbhwdb_backend::parser::{self, LabelParser}; /// assert!(parser::oxy_u4::unknown().parse("AKV 522").is_ok()); /// ``` -pub fn unknown() -> &'static impl LabelParser { - single_parser!(OxyU4, r#"^AKV\ ([0-9])([0-9]{2})$"#, move |c| { - Ok(OxyU4 { +pub fn unknown() -> &'static impl LabelParser { + single_parser!(GenericPart, r#"^AKV\ ([0-9])([0-9]{2})$"#, move |c| { + Ok(GenericPart { kind: "AKV".to_owned(), manufacturer: None, - year: Some(year1(&c[1])?), - week: Some(week2(&c[2])?), + date_code: Some(PartDateCode::YearWeek { + year: year1(&c[1])?, + week: week2(&c[2])?, + }), }) }) } -pub fn oxy_u4() -> &'static impl LabelParser { +pub fn oxy_u4() -> &'static impl LabelParser { unknown() } diff --git a/backend/src/parser/oxy_u5.rs b/backend/src/parser/oxy_u5.rs index 1cc509644..bd131e272 100644 --- a/backend/src/parser/oxy_u5.rs +++ b/backend/src/parser/oxy_u5.rs @@ -2,30 +2,33 @@ // // SPDX-License-Identifier: MIT -use super::{week2, year2, ChipYearWeek, LabelParser}; -use crate::macros::single_parser; - -pub type OxyU5 = ChipYearWeek; +use super::{week2, year2, LabelParser}; +use crate::{ + macros::single_parser, + parser::{GenericPart, PartDateCode}, +}; /// ``` /// use gbhwdb_backend::parser::{self, LabelParser}; /// assert!(parser::oxy_u5::unknown().parse("CP6465 B 02 KOR0531 635963").is_ok()); /// ``` -pub fn unknown() -> &'static impl LabelParser { +pub fn unknown() -> &'static impl LabelParser { single_parser!( - OxyU5, + GenericPart, r#"^CP6465\ B\ 0[0-9]\ KOR([0-9]{2})([0-9]{2})\ [0-9]{6}$"#, move |c| { - Ok(OxyU5 { + Ok(GenericPart { kind: "CP6465".to_owned(), manufacturer: None, - year: Some(year2(&c[1])?), - week: Some(week2(&c[2])?), + date_code: Some(PartDateCode::YearWeek { + year: year2(&c[1])?, + week: week2(&c[2])?, + }), }) }, ) } -pub fn oxy_u5() -> &'static impl LabelParser { +pub fn oxy_u5() -> &'static impl LabelParser { unknown() } diff --git a/backend/src/parser/rohm.rs b/backend/src/parser/rohm.rs new file mode 100644 index 000000000..bd22eee91 --- /dev/null +++ b/backend/src/parser/rohm.rs @@ -0,0 +1,179 @@ +// SPDX-FileCopyrightText: Joonas Javanainen +// +// SPDX-License-Identifier: MIT + +use nom::{ + branch::alt, + bytes::streaming::tag, + character::streaming::{char, one_of}, + combinator::recognize, + sequence::tuple, + Parser as _, +}; + +use super::{ + for_nom::{alnum_uppers, digits, month1_123abc, year1, year1_week2}, + Eeprom, GenericPart, Manufacturer, NomParser, PartDateCode, +}; + +/// ROHM ??9853 EEPROM (SOP-8) +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::rohm::ROHM_9853.parse("9853 2A46").is_ok()); +/// assert!(parser::rohm::ROHM_9853.parse("9853 6912").is_ok()); +/// ``` +pub static ROHM_9853: NomParser = NomParser { + name: "ROHM 9853", + f: |input| { + tuple((tag("9853"), char(' '), year1, month1_123abc, digits(2))) + .map(|(kind, _, year, month, _)| Eeprom { + kind: String::from(kind), + manufacturer: Some(Manufacturer::Rohm), + date_code: Some(PartDateCode::YearMonth { year, month }), + }) + .parse(input) + }, +}; + +/// ROHM ??9854 EEPROM (SOP-8) +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::rohm::ROHM_9854.parse("9854 5S95W").is_ok()); +/// ``` +pub static ROHM_9854: NomParser = NomParser { + name: "ROHM 9854", + f: |input| { + tuple(( + tag("9854"), + char(' '), + year1, + alnum_uppers(1), + digits(2), + char('W'), + )) + .map(|(kind, _, year, _, _, _)| Eeprom { + kind: String::from(kind), + manufacturer: Some(Manufacturer::Rohm), + date_code: Some(PartDateCode::Year { year }), + }) + .parse(input) + }, +}; + +/// ROHM BA6129 +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::rohm::ROHM_BA6129.parse("6129 4803").is_ok()); +/// assert!(parser::rohm::ROHM_BA6129.parse("6129A 6194").is_ok()); +/// ``` +pub static ROHM_BA6129: NomParser = NomParser { + name: "ROHM BA6129", + f: |input| { + tuple(( + alt((tag("6129A"), tag("6129"))), + char(' '), + year1, + alnum_uppers(1), + digits(2), + )) + .map(|(kind, _, year, _, _)| GenericPart { + kind: format!("BA{kind}"), + manufacturer: Some(Manufacturer::Rohm), + date_code: Some(PartDateCode::Year { year }), + }) + .parse(input) + }, +}; + +/// ROHM BA6735 +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::rohm::ROHM_BA6735.parse("6735 8C19").is_ok()); +/// ``` +pub static ROHM_BA6735: NomParser = NomParser { + name: "ROHM BA6735", + f: |input| { + tuple((tag("6735"), char(' '), year1, month1_123abc, digits(2))) + .map(|(_, _, year, month, _)| GenericPart { + kind: "BA6735".to_owned(), + manufacturer: Some(Manufacturer::Rohm), + date_code: Some(PartDateCode::YearMonth { year, month }), + }) + .parse(input) + }, +}; + +/// ROHM ??9750 +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::rohm::ROHM_9750.parse("9750A 1581").is_ok()); +/// assert!(parser::rohm::ROHM_9750.parse("9750B 2A69").is_ok()); +/// ``` +pub static ROHM_9750: NomParser = NomParser { + name: "ROHM 9750", + f: |input| { + tuple(( + recognize(tag("9750").and(one_of("AB"))), + char(' '), + year1, + month1_123abc, + digits(2), + )) + .map(|(kind, _, year, month, _)| GenericPart { + kind: String::from(kind), + manufacturer: Some(Manufacturer::Rohm), + date_code: Some(PartDateCode::YearMonth { year, month }), + }) + .parse(input) + }, +}; + +/// ROHM ??9753 +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::rohm::ROHM_9753.parse("9753 4862").is_ok()); +/// ``` +pub static ROHM_9753: NomParser = NomParser { + name: "ROHM 9753", + f: |input| { + tuple((tag("9753"), char(' '), year1, month1_123abc, digits(2))) + .map(|(kind, _, year, month, _)| GenericPart { + kind: String::from(kind), + manufacturer: Some(Manufacturer::Rohm), + date_code: Some(PartDateCode::YearMonth { year, month }), + }) + .parse(input) + }, +}; + +/// BH7835AFS AGB amplifier +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::rohm::ROHM_BH7835AFS.parse("BH7835AFS 337 T22").is_ok()); +/// ``` +pub static ROHM_BH7835AFS: NomParser = NomParser { + name: "ROHM BH7835AFS", + f: |input| { + tuple(( + tag("BH7835AFS"), + char(' '), + year1_week2, + char(' '), + alnum_uppers(1), + digits(2), + )) + .map(|(kind, _, date_code, _, _, _)| GenericPart { + kind: String::from(kind), + manufacturer: Some(Manufacturer::Rohm), + date_code: Some(date_code), + }) + .parse(input) + }, +}; diff --git a/backend/src/parser/rtc.rs b/backend/src/parser/rtc.rs deleted file mode 100644 index 5182c1ea0..000000000 --- a/backend/src/parser/rtc.rs +++ /dev/null @@ -1,113 +0,0 @@ -// SPDX-FileCopyrightText: 2017-2023 Joonas Javanainen -// -// SPDX-License-Identifier: MIT - -use nom::{bytes::streaming::tag, error::ParseError, sequence::tuple, Parser}; - -use super::{for_nom::year2_week2, toshiba, GenericChip, LabelParser, Manufacturer}; -use crate::macros::multi_parser; - -pub mod sop_8 { - use nom::{bytes::streaming::tag, character::streaming::char, sequence::tuple, Parser}; - - use super::Rtc; - use crate::parser::{for_nom::alnum_uppers, seiko, ChipDateCode, Manufacturer, NomParser}; - - /// Seiko S-3511A (SOP-8) - /// - /// ``` - /// use gbhwdb_backend::parser::{self, LabelParser}; - /// assert!(parser::rtc::sop_8::SEIKO_S3511A.parse("S3511 AV31 9812").is_ok()); - /// assert!(parser::rtc::sop_8::SEIKO_S3511A.parse("S3511 AVEX 2753").is_ok()); - /// ``` - pub static SEIKO_S3511A: NomParser = NomParser { - name: "Seiko S-3511A", - f: |input| { - tuple(( - tag("S3511 AV"), - seiko::year1, - alnum_uppers(1), - char(' '), - seiko::lot_code, - )) - .map(|(_, year, _, _, _)| Rtc { - kind: String::from("S-3511A"), - manufacturer: Some(Manufacturer::Seiko), - date_code: Some(ChipDateCode::Year { year }), - }) - .parse(input) - }, - }; - - /// Seiko S-3516AE (SOP-8) - /// - /// ``` - /// use gbhwdb_backend::parser::{self, LabelParser}; - /// assert!(parser::rtc::sop_8::SEIKO_S3516AE.parse("S3516 AEV42 7505").is_ok()); - /// ``` - pub static SEIKO_S3516AE: NomParser = NomParser { - name: "Seiko S-3516AE", - f: |input| { - tuple(( - tag("S3516 AEV"), - seiko::year1, - alnum_uppers(1), - char(' '), - seiko::lot_code, - )) - .map(|(_, year, _, _, _)| Rtc { - kind: String::from("S-3516AE"), - manufacturer: Some(Manufacturer::Seiko), - date_code: Some(ChipDateCode::Year { year }), - }) - .parse(input) - }, - }; -} - -pub mod sop_20 { - use nom::Parser as _; - - use super::{toshiba_tc8521a, Rtc}; - use crate::parser::{toshiba, NomParser}; - - /// Toshiba TC8521AM (SOP-20) - /// - /// Source: - /// "TOSHIBA TC8521AP, TC8521AM (Real Time Clock II)" - /// - /// ``` - /// use gbhwdb_backend::parser::{self, LabelParser}; - /// assert!(parser::rtc::sop_20::TOSHIBA_TC8521AM.parse("T 9722HB 8521AM").is_ok()); - /// ``` - pub static TOSHIBA_TC8521AM: NomParser = NomParser { - name: "Toshiba TC8521AM", - f: |input| toshiba_tc8521a(toshiba::Package::SOP).parse(input), - }; -} - -fn toshiba_tc8521a<'a, E: ParseError<&'a str>>( - package: toshiba::Package, -) -> impl Parser<&'a str, Rtc, E> { - tuple(( - tag("T "), - year2_week2, - tag("HB 8521A"), - nom::character::streaming::char(package.code_char()), - )) - .map(move |(_, date_code, _, package_code)| Rtc { - kind: format!("TC8521A{package_code}"), - manufacturer: Some(Manufacturer::Toshiba), - date_code: Some(date_code), - }) -} - -pub type Rtc = GenericChip; - -pub fn rtc_sop_8() -> &'static impl LabelParser { - multi_parser!(Rtc, &sop_8::SEIKO_S3511A, &sop_8::SEIKO_S3516AE) -} - -pub fn rtc_sop_20() -> &'static impl LabelParser { - multi_parser!(Rtc, &sop_20::TOSHIBA_TC8521AM) -} diff --git a/backend/src/parser/sanyo.rs b/backend/src/parser/sanyo.rs new file mode 100644 index 000000000..a698efa49 --- /dev/null +++ b/backend/src/parser/sanyo.rs @@ -0,0 +1,111 @@ +// SPDX-FileCopyrightText: Joonas Javanainen +// +// SPDX-License-Identifier: MIT + +use nom::{ + bytes::streaming::tag, + character::streaming::{char, one_of}, + combinator::{opt, recognize}, + error::ParseError, + sequence::tuple, + IResult, Parser as _, +}; + +use super::{sram::Ram, GenericPart}; +use crate::parser::{ + for_nom::{alnum_uppers, digits, month1_abc, uppers, year1}, + Manufacturer, NomParser, PartDateCode, +}; + +/// Sanyo LE26FV10 (TSOP-I-32, 3.3V) +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::sanyo::SANYO_LE26FV10.parse("LE26FV10N1TS-10 3MU50").is_ok()); +/// assert!(parser::sanyo::SANYO_LE26FV10.parse("LE26FV10N1TS-10 4DU2A").is_ok()); +/// ``` +pub static SANYO_LE26FV10: NomParser = NomParser { + name: "Sanyo LE26FV10", + f: |input| { + tuple(( + tag("LE26FV10N1"), + tag("TS-10"), // package, speed + char(' '), + date_code, + uppers(1), + digits(1), + alnum_uppers(1), + )) + .map(|(kind, attrs, _, date_code, _, _, _)| GenericPart { + kind: format!("{kind}{attrs}"), + manufacturer: Some(Manufacturer::Sanyo), + date_code: Some(date_code), + }) + .parse(input) + }, +}; + +/// Sanyo LC35256 (SOP-28, 2.7-5.5V) +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::sanyo::SANYO_LC35256.parse("SANYO LC35256DM-70W JAPAN 0EUPG").is_ok()); +/// assert!(parser::sanyo::SANYO_LC35256.parse("SANYO LC35256FM-70U JAPAN 0LK5G").is_ok()); +/// ``` +pub static SANYO_LC35256: NomParser = NomParser { + name: "Sanyo LC35256", + f: |input| { + tuple(( + tag("SANYO "), + recognize(tag("LC35256").and(opt(one_of("ABCDEF")))), + char('M'), + char('-'), + tag("70"), + alnum_uppers(1), + tag(" JAPAN "), + date_code, + alnum_uppers(3), + )) + .map(|(_, kind, package, _, speed, _, _, date_code, _)| Ram { + kind: format!("{kind}{package}-{speed}"), + manufacturer: Some(Manufacturer::Sanyo), + date_code: Some(date_code), + }) + .parse(input) + }, +}; + +/// Sanyo LC3564 (SOP-28, 2.7-5.5V) +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::sanyo::SANYO_LC3564.parse("SANYO LC3564BM-70 JAPAN 9MUBG").is_ok()); +/// ``` +pub static SANYO_LC3564: NomParser = NomParser { + name: "Sanyo LC3564", + f: |input| { + tuple(( + tag("SANYO "), + recognize(tag("LC3564").and(opt(one_of("AB")))), + char('M'), + char('-'), + tag("70"), + tag(" JAPAN "), + date_code, + alnum_uppers(3), + )) + .map(|(_, kind, package, _, speed, _, date_code, _)| Ram { + kind: format!("{kind}{package}-{speed}"), + manufacturer: Some(Manufacturer::Sanyo), + date_code: Some(date_code), + }) + .parse(input) + }, +}; + +fn date_code<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&'a str, PartDateCode, E> { + year1 + .and(month1_abc) + .map(|(year, month)| PartDateCode::YearMonth { year, month }) + .parse(input) +} diff --git a/backend/src/parser/seiko.rs b/backend/src/parser/seiko.rs new file mode 100644 index 000000000..989f38ff1 --- /dev/null +++ b/backend/src/parser/seiko.rs @@ -0,0 +1,134 @@ +// SPDX-FileCopyrightText: Joonas Javanainen +// +// SPDX-License-Identifier: MIT + +use nom::{ + branch::alt, + bytes::streaming::tag, + character::streaming::{anychar, char}, + combinator::{map_opt, recognize}, + error::ParseError, + sequence::tuple, + IResult, Parser, +}; + +use super::{ + for_nom::{alnum_uppers, digits, month1_123xyz}, + GenericPart, Manufacturer, NomParser, PartDateCode, Year, +}; + +/// Seiko S-3511A (SOP-8) +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::seiko::SEIKO_S3511A.parse("S3511 AV31 9812").is_ok()); +/// assert!(parser::seiko::SEIKO_S3511A.parse("S3511 AVEX 2753").is_ok()); +/// ``` +pub static SEIKO_S3511A: NomParser = NomParser { + name: "Seiko S-3511A", + f: |input| { + tuple((tag("S3511 AV"), date_code, char(' '), lot_code)) + .map(|(_, date_code, _, _)| GenericPart { + kind: String::from("S-3511A"), + manufacturer: Some(Manufacturer::Seiko), + date_code: Some(date_code), + }) + .parse(input) + }, +}; + +/// Seiko S-3516AE (SOP-8) +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::seiko::SEIKO_S3516AE.parse("S3516 AEV42 7505").is_ok()); +/// ``` +pub static SEIKO_S3516AE: NomParser = NomParser { + name: "Seiko S-3516AE", + f: |input| { + tuple((tag("S3516 AEV"), date_code, char(' '), lot_code)) + .map(|(_, date_code, _, _)| GenericPart { + kind: String::from("S-3516AE"), + manufacturer: Some(Manufacturer::Seiko), + date_code: Some(date_code), + }) + .parse(input) + }, +}; + +/// Seiko S-6403 +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::seiko::SEIKO_S6403.parse("S6403 CU4E0 9723").is_ok()); +/// ``` +pub static SEIKO_S6403: NomParser = NomParser { + name: "Seiko S-6403", + f: |input| { + tuple(( + alt(( + tag("S6403 AU").map(|_| "S-6403A"), + tag("S6403 CU").map(|_| "S-6403C"), + )), + year1, + alnum_uppers(1), + digits(1), + char(' '), + lot_code, + )) + .map(|(kind, year, _, _, _, _)| GenericPart { + kind: String::from(kind), + manufacturer: Some(Manufacturer::Seiko), + date_code: Some(PartDateCode::Year { year }), + }) + .parse(input) + }, +}; + +/// Seiko S-6960E +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::seiko::SEIKO_S6960E.parse("S6960 E-U2Z C700").is_ok()); +/// assert!(parser::seiko::SEIKO_S6960E.parse("S6960 E-U2X C410").is_ok()); +/// ``` +pub static SEIKO_S6960E: NomParser = NomParser { + name: "Seiko S-6960E", + f: |input| { + tuple((tag("S6960 E-U"), date_code, char(' '), lot_code)) + .map(|(_, date_code, _, _)| GenericPart { + kind: String::from("S-6960E"), + manufacturer: Some(Manufacturer::Seiko), + date_code: Some(date_code), + }) + .parse(input) + }, +}; + +fn date_code<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&'a str, PartDateCode, E> { + year1 + .and(month1_123xyz) + .map(|(year, month)| PartDateCode::YearMonth { year, month }) + .parse(input) +} + +fn year1<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&'a str, Year, E> { + map_opt(anychar, |ch| match ch { + '0' => Some(Year::Partial(0)), + '1' | 'A' => Some(Year::Partial(1)), + '2' | 'B' => Some(Year::Partial(2)), + '3' | 'C' => Some(Year::Partial(3)), + '4' | 'D' => Some(Year::Partial(4)), + '5' | 'E' => Some(Year::Partial(5)), + '6' | 'F' => Some(Year::Partial(6)), + '7' | 'G' => Some(Year::Partial(7)), + '8' | 'H' => Some(Year::Partial(8)), + '9' | 'J' => Some(Year::Partial(9)), + _ => None, + }) + .parse(input) +} + +fn lot_code<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&'a str, &str, E> { + recognize(alnum_uppers(1).and(digits(3))).parse(input) +} diff --git a/backend/src/parser/sharp.rs b/backend/src/parser/sharp.rs new file mode 100644 index 000000000..3f232659a --- /dev/null +++ b/backend/src/parser/sharp.rs @@ -0,0 +1,153 @@ +// SPDX-FileCopyrightText: Joonas Javanainen +// +// SPDX-License-Identifier: MIT + +use nom::{ + bytes::streaming::tag, + character::streaming::char, + combinator::{opt, value}, + error::ParseError, + sequence::tuple, + Parser, +}; + +use super::{ + for_nom::{alphas, year2_week2}, + GenericPart, Manufacturer, NomParser, +}; + +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::sharp::SHARP_IR3E02.parse("DMG-REG IR3E02 9527 CB").is_ok()); +/// assert!(parser::sharp::SHARP_IR3E02.parse("DMG-REG IR3E02 9820 n").is_ok()); +/// assert!(parser::sharp::SHARP_IR3E02.parse("DMG-REG IR3E02 9024 J").is_ok()); +/// ``` +pub static SHARP_IR3E02: NomParser = NomParser { + name: "Sharp IR3E02", + f: |input| ir3_old("DMG-REG", "IR3E02").parse(input), +}; + +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::sharp::SHARP_IR3E06.parse("CGB-REG IR3E06N 9839 C").is_ok()); +/// assert!(parser::sharp::SHARP_IR3E06.parse("CGB-REG IR3E06N 0046 A").is_ok()); +/// ``` +pub static SHARP_IR3E06: NomParser = NomParser { + name: "Sharp IR3E06", + f: |input| ir3("CGB-REG", "IR3E06", Package::Ssop18).parse(input), +}; + +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::sharp::SHARP_IR3E09.parse("AGB-REG IR3E09N 0104 C").is_ok()); +/// assert!(parser::sharp::SHARP_IR3E09.parse("AGB-REG IR3E09N 0141 K").is_ok()); +/// assert!(parser::sharp::SHARP_IR3E09.parse("AGB-REG IR3E09N 0204 d").is_ok()); +/// assert!(parser::sharp::SHARP_IR3E09.parse("AGB-REG IR3E09N AA24 A").is_ok()); +/// assert!(parser::sharp::SHARP_IR3E09.parse("AGB-REG IR3E09N 0223 B").is_ok()); +/// ``` +pub static SHARP_IR3E09: NomParser = NomParser { + name: "Sharp IR3E09", + f: |input| ir3("AGB-REG", "IR3E09", Package::Ssop18).parse(input), +}; + +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::sharp::SHARP_IR3R40.parse("DMG-AMP IR3R40 9222 AA").is_ok()); +/// assert!(parser::sharp::SHARP_IR3R40.parse("DMG-AMP IR3R40 8909 A").is_ok()); +/// ``` +pub static SHARP_IR3R40: NomParser = NomParser { + name: "Sharp IR3R40", + f: |input| ir3_old("DMG-AMP", "IR3R40").parse(input), +}; + +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::sharp::SHARP_IR3R53.parse("AMP MGB IR3R53N 9806 a").is_ok()); +/// assert!(parser::sharp::SHARP_IR3R53.parse("AMP MGB IR3R53N 9724 C").is_ok()); +/// ``` +pub static SHARP_IR3R53: NomParser = NomParser { + name: "Sharp IR3R53", + f: |input| ir3("AMP MGB", "IR3R53", Package::Ssop18).parse(input), +}; + +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::sharp::SHARP_IR3R56.parse("AMP MGB IR3R56N 0046 A").is_ok()); +/// assert!(parser::sharp::SHARP_IR3R56.parse("AMP MGB IR3R56N 0040 C").is_ok()); +/// ``` +pub static SHARP_IR3R56: NomParser = NomParser { + name: "Sharp IR3R56", + f: |input| ir3("AMP MGB", "IR3R56", Package::Ssop18).parse(input), +}; + +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::sharp::SHARP_IR3R60.parse("AMP AGB IR3R60N 0103 a").is_ok()); +/// assert!(parser::sharp::SHARP_IR3R60.parse("AMP AGB IR3R60N 0240 N").is_ok()); +/// ``` +pub static SHARP_IR3R60: NomParser = NomParser { + name: "Sharp IR3R60", + f: |input| ir3("AMP AGB", "IR3R60", Package::Ssop18).parse(input), +}; + +fn ir3<'a, E: ParseError<&'a str>>( + prefix: &'static str, + kind: &'static str, + pkg: Package, +) -> impl Parser<&'a str, GenericPart, E> { + tuple(( + tag(prefix), + char(' '), + tag(kind), + package(pkg), + char(' '), + year2_week2, + char(' '), + alphas(1), + )) + .map(|(_, _, kind, package, _, date_code, _, _)| GenericPart { + kind: format!("{kind}{package}", package = package.code()), + manufacturer: Some(Manufacturer::Sharp), + date_code: Some(date_code), + }) +} + +fn ir3_old<'a, E: ParseError<&'a str>>( + prefix: &'static str, + kind: &'static str, +) -> impl Parser<&'a str, GenericPart, E> { + tuple(( + tag(prefix), + char(' '), + tag(kind), + char(' '), + year2_week2, + char(' '), + alphas(1), + opt(nom::character::complete::satisfy(|c| { + c.is_ascii_uppercase() + })), + )) + .map(|(_, _, kind, _, date_code, _, _, _)| GenericPart { + kind: String::from(kind), + manufacturer: Some(Manufacturer::Sharp), + date_code: Some(date_code), + }) +} + +fn package<'a, E: ParseError<&'a str>>(package: Package) -> impl Parser<&'a str, Package, E> { + value(package, tag(package.code())) +} + +#[derive(Copy, Clone, Debug, PartialEq, Eq)] +enum Package { + Ssop18, +} + +impl Package { + pub const fn code(&self) -> &'static str { + match self { + Package::Ssop18 => "N", + } + } +} diff --git a/backend/src/parser/sram.rs b/backend/src/parser/sram.rs index dc6556a1b..df694870c 100644 --- a/backend/src/parser/sram.rs +++ b/backend/src/parser/sram.rs @@ -1,27 +1,20 @@ -use super::{LabelParser, Manufacturer, ParsedData, Year}; +// SPDX-FileCopyrightText: Joonas Javanainen +// +// SPDX-License-Identifier: MIT + +use super::{LabelParser, Manufacturer}; use crate::{ macros::{multi_parser, single_parser}, - parser::{week2, year1, year2, ChipDateCode, GenericChip}, - time::Week, + parser::{ + amic, bsi, fujitsu, hynix, hyundai, lgs, nec, sanyo, st_micro, toshiba, victronix, week2, + winbond, year1, year2, GenericPart, PartDateCode, + }, }; pub mod sop_28; -pub mod sop_32; pub mod tsop_i_28; -pub mod tsop_i_48; - -#[derive(Clone, Debug, Eq, PartialEq)] -pub struct StaticRam { - pub family: Option<&'static str>, - pub part: Option, - pub manufacturer: Option, - pub year: Option, - pub week: Option, -} - -impl ParsedData for StaticRam {} -pub type Ram = GenericChip; +pub type Ram = GenericPart; /// LSI Logic LH52xx 64 kbit /// @@ -39,7 +32,7 @@ pub fn lsi_logic_lh52xx() -> &'static impl LabelParser { Ok(Ram { kind: c[1].to_owned(), manufacturer: Some(Manufacturer::LsiLogic), - date_code: Some(ChipDateCode::YearWeek { + date_code: Some(PartDateCode::YearWeek { year: year1(&c[2])?, week: week2(&c[3])?, }), @@ -48,7 +41,7 @@ pub fn lsi_logic_lh52xx() -> &'static impl LabelParser { ) } -/// LSI Logic LH52B256 +/// LSI Logic LH52B256 (4.5-5.5V) /// /// ``` /// use gbhwdb_backend::parser::{self, LabelParser}; @@ -62,7 +55,7 @@ pub fn lsi_logic_lh52b256() -> &'static impl LabelParser { Ok(Ram { kind: c[1].to_owned(), manufacturer: Some(Manufacturer::LsiLogic), - date_code: Some(ChipDateCode::YearWeek { + date_code: Some(PartDateCode::YearWeek { year: year1(&c[2])?, week: week2(&c[3])?, }), @@ -71,7 +64,7 @@ pub fn lsi_logic_lh52b256() -> &'static impl LabelParser { ) } -/// LSI Logic LH5168 +/// LSI Logic LH5168 (4.5-5.5V) /// /// ``` /// use gbhwdb_backend::parser::{self, LabelParser}; @@ -85,7 +78,7 @@ pub fn lsi_logic_lh5168() -> &'static impl LabelParser { Ok(Ram { kind: c[1].to_owned(), manufacturer: Some(Manufacturer::LsiLogic), - date_code: Some(ChipDateCode::YearWeek { + date_code: Some(PartDateCode::YearWeek { year: year1(&c[2])?, week: week2(&c[3])?, }), @@ -94,7 +87,7 @@ pub fn lsi_logic_lh5168() -> &'static impl LabelParser { ) } -/// Mosel-Vitelic LH52B256 +/// Mosel-Vitelic LH52B256 (4.5-5.5V) /// /// ``` /// use gbhwdb_backend::parser::{self, LabelParser}; @@ -108,7 +101,7 @@ pub fn mosel_vitelic_lh52b256() -> &'static impl LabelParser { Ok(Ram { kind: c[1].to_owned(), manufacturer: Some(Manufacturer::MoselVitelic), - date_code: Some(ChipDateCode::YearWeek { + date_code: Some(PartDateCode::YearWeek { year: year1(&c[2])?, week: week2(&c[3])?, }), @@ -117,7 +110,7 @@ pub fn mosel_vitelic_lh52b256() -> &'static impl LabelParser { ) } -/// Mosel-Vitelic LH5168 +/// Mosel-Vitelic LH5168 (4.5-5.5V) /// /// ``` /// use gbhwdb_backend::parser::{self, LabelParser}; @@ -132,7 +125,7 @@ pub fn mosel_vitelic_lh5168() -> &'static impl LabelParser { Ok(Ram { kind: c[1].to_owned(), manufacturer: Some(Manufacturer::MoselVitelic), - date_code: Some(ChipDateCode::YearWeek { + date_code: Some(PartDateCode::YearWeek { year: year1(&c[2])?, week: week2(&c[3])?, }), @@ -141,7 +134,7 @@ pub fn mosel_vitelic_lh5168() -> &'static impl LabelParser { ) } -/// Mosel-Vitelic LH5268A +/// Mosel-Vitelic LH5268A (4.5-5.5V) /// /// ``` /// use gbhwdb_backend::parser::{self, LabelParser}; @@ -155,7 +148,7 @@ pub fn mosel_vitelic_lh5268a() -> &'static impl LabelParser { Ok(Ram { kind: c[1].to_owned(), manufacturer: Some(Manufacturer::MoselVitelic), - date_code: Some(ChipDateCode::YearWeek { + date_code: Some(PartDateCode::YearWeek { year: year1(&c[2])?, week: week2(&c[3])?, }), @@ -164,7 +157,7 @@ pub fn mosel_vitelic_lh5268a() -> &'static impl LabelParser { ) } -/// Sharp LH5160 +/// Sharp LH5160 (4.5-5.5V) /// /// ``` /// use gbhwdb_backend::parser::{self, LabelParser}; @@ -178,7 +171,7 @@ pub fn sharp_lh5160() -> &'static impl LabelParser { Ok(Ram { kind: c[1].to_owned(), manufacturer: Some(Manufacturer::Sharp), - date_code: Some(ChipDateCode::YearWeek { + date_code: Some(PartDateCode::YearWeek { year: year2(&c[2])?, week: week2(&c[3])?, }), @@ -187,7 +180,7 @@ pub fn sharp_lh5160() -> &'static impl LabelParser { ) } -/// Sharp LH5168 +/// Sharp LH5168 (4.5-5.5V) /// /// ``` /// use gbhwdb_backend::parser::{self, LabelParser}; @@ -203,7 +196,7 @@ pub fn sharp_lh5168() -> &'static impl LabelParser { Ok(Ram { kind: c[1].to_owned(), manufacturer: Some(Manufacturer::Sharp), - date_code: Some(ChipDateCode::YearWeek { + date_code: Some(PartDateCode::YearWeek { year: year2(&c[2])?, week: week2(&c[3])?, }), @@ -226,7 +219,7 @@ pub fn sharp_lh5164an() -> &'static impl LabelParser { Ok(Ram { kind: c[1].to_owned(), manufacturer: Some(Manufacturer::Sharp), - date_code: Some(ChipDateCode::YearWeek { + date_code: Some(PartDateCode::YearWeek { year: year2(&c[2])?, week: week2(&c[3])?, }), @@ -249,7 +242,7 @@ pub fn sharp_lh5164an_2() -> &'static impl LabelParser { Ok(Ram { kind: c[1].to_owned(), manufacturer: Some(Manufacturer::Sharp), - date_code: Some(ChipDateCode::YearWeek { + date_code: Some(PartDateCode::YearWeek { year: year2(&c[2])?, week: week2(&c[3])?, }), @@ -272,7 +265,7 @@ pub fn sharp_lh5164ln() -> &'static impl LabelParser { Ok(Ram { kind: c[1].to_owned(), manufacturer: Some(Manufacturer::Sharp), - date_code: Some(ChipDateCode::YearWeek { + date_code: Some(PartDateCode::YearWeek { year: year2(&c[2])?, week: week2(&c[3])?, }), @@ -296,7 +289,7 @@ pub fn sharp_lh5264n() -> &'static impl LabelParser { Ok(Ram { kind: c[1].to_owned(), manufacturer: Some(Manufacturer::Sharp), - date_code: Some(ChipDateCode::YearWeek { + date_code: Some(PartDateCode::YearWeek { year: year2(&c[2])?, week: week2(&c[3])?, }), @@ -319,7 +312,7 @@ pub fn sharp_lh5264tn_l() -> &'static impl LabelParser { Ok(Ram { kind: c[1].to_owned(), manufacturer: Some(Manufacturer::Sharp), - date_code: Some(ChipDateCode::YearWeek { + date_code: Some(PartDateCode::YearWeek { year: year2(&c[2])?, week: week2(&c[3])?, }), @@ -342,7 +335,7 @@ pub fn sharp_lh5164n() -> &'static impl LabelParser { Ok(Ram { kind: c[1].to_owned(), manufacturer: Some(Manufacturer::Sharp), - date_code: Some(ChipDateCode::YearWeek { + date_code: Some(PartDateCode::YearWeek { year: year2(&c[2])?, week: week2(&c[3])?, }), @@ -365,7 +358,7 @@ pub fn sharp_lh52a64n_l() -> &'static impl LabelParser { Ok(Ram { kind: c[1].to_owned(), manufacturer: Some(Manufacturer::Sharp), - date_code: Some(ChipDateCode::YearWeek { + date_code: Some(PartDateCode::YearWeek { year: year2(&c[2])?, week: week2(&c[3])?, }), @@ -388,7 +381,7 @@ pub fn crosslink_lh52a64n_yl() -> &'static impl LabelParser { Ok(Ram { kind: c[1].to_owned(), manufacturer: Some(Manufacturer::Crosslink), - date_code: Some(ChipDateCode::YearWeek { + date_code: Some(PartDateCode::YearWeek { year: year1(&c[2])?, week: week2(&c[3])?, }), @@ -397,7 +390,7 @@ pub fn crosslink_lh52a64n_yl() -> &'static impl LabelParser { ) } -/// Crosslink LH5268ANF-10YLL +/// Crosslink LH5268ANF-10YLL (4.5-5.5V) /// /// ``` /// use gbhwdb_backend::parser::{self, LabelParser}; @@ -411,7 +404,7 @@ pub fn crosslink_lh5268anf() -> &'static impl LabelParser { Ok(Ram { kind: c[1].to_owned(), manufacturer: Some(Manufacturer::Crosslink), - date_code: Some(ChipDateCode::YearWeek { + date_code: Some(PartDateCode::YearWeek { year: year1(&c[2])?, week: week2(&c[3])?, }), @@ -434,7 +427,7 @@ pub fn mosel_vitelic_lh52a64n_pl() -> &'static impl LabelParser { Ok(Ram { kind: c[1].to_owned(), manufacturer: Some(Manufacturer::MoselVitelic), - date_code: Some(ChipDateCode::YearWeek { + date_code: Some(PartDateCode::YearWeek { year: year1(&c[2])?, week: week2(&c[3])?, }), @@ -443,47 +436,22 @@ pub fn mosel_vitelic_lh52a64n_pl() -> &'static impl LabelParser { ) } -/// Hynix HY62WT08081E (SOP-28 or TSOP-I-28) -/// -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::sram::hynix_hy62wt08081e().parse("hynix 0231A HY62WT081ED70C KOREA").is_ok()); -/// ``` -pub fn hynix_hy62wt08081e() -> &'static impl LabelParser { - single_parser!( - Ram, - r#"^hynix\ ([0-9]{2})([0-9]{2})[A-Z]\ (HY62WT081E[LD][0-9][0-9][CEI])\ KOREA$"#, - move |c| { - Ok(Ram { - kind: c[3].to_owned(), - manufacturer: Some(Manufacturer::Hynix), - date_code: Some(ChipDateCode::YearWeek { - year: year2(&c[1])?, - week: week2(&c[2])?, - }), - }) - }, - ) -} - -pub fn sram_sop_28() -> &'static impl LabelParser { +pub fn sram_sop_28_5v() -> &'static impl LabelParser { multi_parser!( Ram, - sop_28::bsi_bs62lv256(), - sop_28::hyundai_gm76c256(), - sop_28::hyundai_gm76v256(), - sop_28::hyundai_hy6264_new(), - sop_28::hyundai_hy6264_old(), - sop_28::lgs_gm76c256(), - sop_28::sanyo_lc35256(), - sop_28::sanyo_lc3564(), + &bsi::BSI_BS62LV256, + &lgs::LGS_GM76C256, + &lgs::HYUNDAI_GM76C256, + &hyundai::HYUNDAI_HY6264, + &sanyo::SANYO_LC35256, + &sanyo::SANYO_LC3564, sop_28::rohm_br62256f(), sop_28::rohm_br6265(), sop_28::rohm_xlj6265(), - sop_28::victronix_vn4464(), - sop_28::winbond_w24257(), - sop_28::winbond_w24258(), - sop_28::winbond_w2465(), + &victronix::VICTRONIX_VN4464, + &winbond::WINBOND_W24257, + &winbond::WINBOND_W24258, + &winbond::WINBOND_W2465, sop_28::sharp_lh52256(), lsi_logic_lh5168(), lsi_logic_lh52b256(), @@ -503,35 +471,46 @@ pub fn sram_sop_28() -> &'static impl LabelParser { crosslink_lh52a64n_yl(), crosslink_lh5268anf(), mosel_vitelic_lh52a64n_pl(), - hynix_hy62wt08081e(), + &hynix::HYNIX_HY62WT08081, + ) +} + +pub fn sram_sop_28_3v3() -> &'static impl LabelParser { + multi_parser!( + Ram, + &bsi::BSI_BS62LV256, + &lgs::HYUNDAI_GM76V256, + &sanyo::SANYO_LC35256, + &sanyo::SANYO_LC3564, + sop_28::sharp_lh52256(), + &hynix::HYNIX_HY62WT08081, ) } -pub fn sram_sop_32() -> &'static impl LabelParser { - multi_parser!(GenericChip, sop_32::hyundai_hy628100(),) +pub fn sram_sop_32_5v() -> &'static impl LabelParser { + multi_parser!(GenericPart, &hyundai::HYUNDAI_HY628100,) } -pub fn sram_tsop_i_28() -> &'static impl LabelParser { +pub fn sram_tsop_i_28() -> &'static impl LabelParser { multi_parser!( - GenericChip, + GenericPart, tsop_i_28::sharp_lh52256(), tsop_i_28::sharp_lh51d256(), tsop_i_28::sharp_lh52cv256(), - hynix_hy62wt08081e(), ) } -pub fn sram_tsop_i_48() -> &'static impl LabelParser { +pub fn sram_tsop_i_48() -> &'static impl LabelParser { multi_parser!( - StaticRam, - tsop_i_48::nec_upd442012a(), - tsop_i_48::nec_upd442012l(), - tsop_i_48::fujitsu_mb82d12160(), - tsop_i_48::hynix_hy62lf16206a(), - tsop_i_48::st_micro_m68as128dl70n6(), - tsop_i_48::amic_lp62s16128bw(), - tsop_i_48::bsi_bs616lv2018(), - tsop_i_48::bsi_bs616lv2019(), - tsop_i_48::toshiba_tc55v200(), + Ram, + &nec::NEC_UPD442012A_X, + &nec::NEC_UPD442012L_X, + &fujitsu::FUJITSU_MB82D12160, + &hynix::HYNIX_HY62LF16206, + &st_micro::ST_MICRO_M68AS128, + &amic::AMIC_LP62S16128, + &bsi::BSI_BS616LV2018, + &bsi::BSI_BS616LV2019, + &toshiba::TOSHIBA_TC55V200 ) } diff --git a/backend/src/parser/sram/sop_28.rs b/backend/src/parser/sram/sop_28.rs index bb7e8f89e..e6f2a4ded 100644 --- a/backend/src/parser/sram/sop_28.rs +++ b/backend/src/parser/sram/sop_28.rs @@ -1,205 +1,10 @@ use super::Ram; use crate::{ macros::single_parser, - parser::{month1_alpha, week2, year1, year2, ChipDateCode, LabelParser, Manufacturer}, + parser::{week2, year1, year2, LabelParser, Manufacturer, PartDateCode}, }; -/// BSI BS62LV256SC (SOP-28) -/// -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::sram::sop_28::bsi_bs62lv256().parse("BSI BS62LV256SC-70 S2827V52155 A0106 TAIWAN").is_ok()); -/// assert!(parser::sram::sop_28::bsi_bs62lv256().parse("BSI BS62LV256SC-70 S2828W11075.1 F0231 TAIWAN").is_ok()); -/// assert!(parser::sram::sop_28::bsi_bs62lv256().parse("BSI BS62LV256SCG70 S2828CA30125 A D05502 TAIWAN").is_ok()); -/// assert!(parser::sram::sop_28::bsi_bs62lv256().parse("BSI BS62LV256SC-70 S2828W13088.1N F0318 TAIWAN").is_ok()); -/// ``` -pub fn bsi_bs62lv256() -> &'static impl LabelParser { - single_parser!( - Ram, - r#"^BSI\ (?BS62LV256)(?S)(?[CI])(?[GP\-])(?(55|70))\ [[:alnum:]]{10,12}(.[0-9][A-Z]?)?(\ A)?\ [A-Z](?[0-9]{2})(?[0-9]{2})[0-9]?\ TAIWAN$"#, - move |c| { - Ok(Ram { - kind: format!( - "{kind}{package}{grade}{material}{speed}", - kind = &c["kind"], - package = &c["package"], - grade = &c["grade"], - material = &c["material"], - speed = &c["speed"], - ), - manufacturer: Some(Manufacturer::Bsi), - date_code: Some(ChipDateCode::YearWeek { - year: year2(&c["year"])?, - week: week2(&c["week"])?, - }), - }) - }, - ) -} - -/// Hyundai GM76C256 (SOP-28) -/// -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::sram::sop_28::hyundai_gm76c256().parse("HYUNDAI GM76C256CLLFW70 0047 KOREA").is_ok()); -/// ``` -pub fn hyundai_gm76c256() -> &'static impl LabelParser { - single_parser!( - Ram, - r#"^HYUNDAI\ (?GM76C256[ABC]LL)FW70\ (?[0-9]{2})(?[0-9]{2})\ KOREA$"#, - move |c| { - Ok(Ram { - kind: c["kind"].to_owned(), - manufacturer: Some(Manufacturer::Hyundai), - date_code: Some(ChipDateCode::YearWeek { - year: year2(&c["year"])?, - week: week2(&c["week"])?, - }), - }) - }, - ) -} - -/// Hyundai GM76V256 (SOP-28) -/// -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::sram::sop_28::hyundai_gm76v256().parse("HYUNDAI GM76V256CLLFW10 0115 KOREA").is_ok()); -/// ``` -pub fn hyundai_gm76v256() -> &'static impl LabelParser { - single_parser!( - Ram, - r#"^HYUNDAI\ (?GM76V256[ABC]LL)FW10\ (?[0-9]{2})(?[0-9]{2})\ KOREA$"#, - move |c| { - Ok(Ram { - kind: c["kind"].to_owned(), - manufacturer: Some(Manufacturer::Hyundai), - date_code: Some(ChipDateCode::YearWeek { - year: year2(&c["year"])?, - week: week2(&c["week"])?, - }), - }) - }, - ) -} - -/// Hyundai HY6264 (1994+) -/// -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::sram::sop_28::hyundai_hy6264_new().parse("HY6264A LLJ-10 9902B KOREA").is_ok()); -/// ``` -pub fn hyundai_hy6264_new() -> &'static impl LabelParser { - single_parser!( - Ram, - r#"^(?HY6264A)\ (?(L|LL))(?J)-(?10|70)\ (?[0-9]{2})(?[0-9]{2})[A-Z]\ KOREA$"#, - move |c| { - Ok(Ram { - kind: format!("{}{}", &c["kind"], &c["power"]), - manufacturer: Some(Manufacturer::Hyundai), - date_code: Some(ChipDateCode::YearWeek { - year: year2(&c["year"])?, - week: week2(&c["week"])?, - }), - }) - }, - ) -} - -/// Hyundai HY6264 (1992-1994) -/// -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::sram::sop_28::hyundai_hy6264_old().parse("HYUNDAI HY6264ALLJ-10 9327B KOREA").is_ok()); -/// ``` -pub fn hyundai_hy6264_old() -> &'static impl LabelParser { - single_parser!( - Ram, - r#"^HYUNDAI\ (?HY6264A)(?(L|LL))(?)J-(?)10\ (?[0-9]{2})(?[0-9]{2})[A-Z]\ KOREA$"#, - move |c| { - Ok(Ram { - kind: format!("{}{}", &c["kind"], &c["power"]), - manufacturer: Some(Manufacturer::Hyundai), - date_code: Some(ChipDateCode::YearWeek { - year: year2(&c["year"])?, - week: week2(&c["week"])?, - }), - }) - }, - ) -} - -/// LGS GM76C256 -/// -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::sram::sop_28::lgs_gm76c256().parse("LGS GM76C256CLLFW70 9849 KOREA").is_ok()); -/// ``` -pub fn lgs_gm76c256() -> &'static impl LabelParser { - single_parser!( - Ram, - r#"^LGS\ (?GM76C256[ABC]LL)FW70\ (?[0-9]{2})(?[0-9]{2})\ KOREA$"#, - move |c| { - Ok(Ram { - kind: c["kind"].to_owned(), - manufacturer: Some(Manufacturer::Lgs), - date_code: Some(ChipDateCode::YearWeek { - year: year2(&c["year"])?, - week: week2(&c["week"])?, - }), - }) - }, - ) -} - -/// Sanyo LC35256 -/// -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::sram::sop_28::sanyo_lc35256().parse("SANYO LC35256DM-70W JAPAN 0EUPG").is_ok()); -/// assert!(parser::sram::sop_28::sanyo_lc35256().parse("SANYO LC35256FM-70U JAPAN 0LK5G").is_ok()); -/// ``` -pub fn sanyo_lc35256() -> &'static impl LabelParser { - single_parser!( - Ram, - r#"^SANYO\ (?LC35256[A-F]?)(?M)-(?[0-9]{2})[[:alnum:]]\ JAPAN\ (?[0-9])(?[A-M])[[:alnum:]]{3}$"#, - move |c| { - Ok(Ram { - kind: c["kind"].to_owned(), - manufacturer: Some(Manufacturer::Sanyo), - date_code: Some(ChipDateCode::YearMonth { - year: year1(&c["year"])?, - month: month1_alpha(&c["month"])?, - }), - }) - }, - ) -} - -/// Sanyo LC3564 -/// -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::sram::sop_28::sanyo_lc3564().parse("SANYO LC3564BM-70 JAPAN 9MUBG").is_ok()); -/// ``` -pub fn sanyo_lc3564() -> &'static impl LabelParser { - single_parser!( - Ram, - r#"^SANYO\ (?LC3564[A-B]?)(?M)-(?[0-9]{2})\ JAPAN\ (?[0-9])(?[A-M])[[:alnum:]]{3}$"#, - move |c| { - Ok(Ram { - kind: c["kind"].to_owned(), - manufacturer: Some(Manufacturer::Sanyo), - date_code: Some(ChipDateCode::YearMonth { - year: year1(&c["year"])?, - month: month1_alpha(&c["month"])?, - }), - }) - }, - ) -} - -/// Rohm BR62256F (SOP-28) +/// Rohm BR62256F (SOP-28, 4.5-5.5V) /// /// ``` /// use gbhwdb_backend::parser::{self, LabelParser}; @@ -218,7 +23,7 @@ pub fn rohm_br62256f() -> &'static impl LabelParser { power = &c["power"], ), manufacturer: Some(Manufacturer::Rohm), - date_code: Some(ChipDateCode::YearWeek { + date_code: Some(PartDateCode::YearWeek { year: year1(&c["year"])?, week: week2(&c["week"])?, }), @@ -227,7 +32,7 @@ pub fn rohm_br62256f() -> &'static impl LabelParser { ) } -/// Rohm BR6265 (SOP-28) +/// Rohm BR6265 (SOP-28, 4.5-5.5V) /// /// ``` /// use gbhwdb_backend::parser::{self, LabelParser}; @@ -246,7 +51,7 @@ pub fn rohm_br6265() -> &'static impl LabelParser { power = &c["power"], ), manufacturer: Some(Manufacturer::Rohm), - date_code: Some(ChipDateCode::YearWeek { + date_code: Some(PartDateCode::YearWeek { year: year1(&c["year"])?, week: week2(&c["week"])?, }), @@ -274,123 +79,7 @@ pub fn rohm_xlj6265() -> &'static impl LabelParser { power = &c["power"], ), manufacturer: Some(Manufacturer::Rohm), - date_code: Some(ChipDateCode::YearWeek { - year: year1(&c["year"])?, - week: week2(&c["week"])?, - }), - }) - }, - ) -} - -/// Victronix VN4464 -/// -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::sram::sop_28::victronix_vn4464().parse("Victronix VN4464S-08LL 95103B029").is_ok()); -/// ``` -pub fn victronix_vn4464() -> &'static impl LabelParser { - single_parser!( - Ram, - r#"^Victronix\ (?VN4464)(?S)-(?08)(?LL)\ (?[0-9]{2})(?[0-9]{2})[0-9][A-Z][0-9]{3}$"#, - move |c| { - Ok(Ram { - kind: format!( - "{kind}{package}-{speed}{power}", - kind = &c["kind"], - package = &c["package"], - speed = &c["speed"], - power = &c["power"], - ), - manufacturer: Some(Manufacturer::Victronix), - date_code: Some(ChipDateCode::YearWeek { - year: year2(&c["year"])?, - week: week2(&c["week"])?, - }), - }) - }, - ) -} - -/// Winbond W24257 -/// -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::sram::sop_28::winbond_w24257().parse("Winbond W24257S-70LL 046QB202858301AC").is_ok()); -/// ``` -pub fn winbond_w24257() -> &'static impl LabelParser { - single_parser!( - Ram, - r#"^Winbond\ (?W24257)(?S)-(?70)(?LL)\ (?[0-9])(?[0-9]{2})[A-Z]{2}[0-9]{9}[A-Z]{2}$"#, - move |c| { - Ok(Ram { - kind: format!( - "{kind}{package}-{speed}{power}", - kind = &c["kind"], - package = &c["package"], - speed = &c["speed"], - power = &c["power"], - ), - manufacturer: Some(Manufacturer::Winbond), - date_code: Some(ChipDateCode::YearWeek { - year: year1(&c["year"])?, - week: week2(&c["week"])?, - }), - }) - }, - ) -} - -/// Winbond W24258 -/// -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::sram::sop_28::winbond_w24258().parse("Winbond W24258S-70LE 011MH200254401AA").is_ok()); -/// ``` -pub fn winbond_w24258() -> &'static impl LabelParser { - single_parser!( - Ram, - r#"^Winbond\ (?W24258)(?S)-(?70)(?LE)\ (?[0-9])(?[0-9]{2})[A-Z]{2}[0-9]{9}[A-Z]{2}$"#, - move |c| { - Ok(Ram { - kind: format!( - "{kind}{package}-{speed}{power}", - kind = &c["kind"], - package = &c["package"], - speed = &c["speed"], - power = &c["power"], - ), - manufacturer: Some(Manufacturer::Winbond), - date_code: Some(ChipDateCode::YearWeek { - year: year1(&c["year"])?, - week: week2(&c["week"])?, - }), - }) - }, - ) -} - -/// Winbond W2465 -/// -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::sram::sop_28::winbond_w2465().parse("Winbond W2465S-70LL 140SD21331480-II1RA").is_ok()); -/// ``` -pub fn winbond_w2465() -> &'static impl LabelParser { - single_parser!( - Ram, - r#"^Winbond\ (?W2465)(?S)-(?70)(?LL)\ (?[0-9])(?[0-9]{2})[A-Z]{2}[0-9]{8}-II1RA$"#, - move |c| { - Ok(Ram { - kind: format!( - "{kind}{package}-{speed}{power}", - kind = &c["kind"], - package = &c["package"], - speed = &c["speed"], - power = &c["power"], - ), - manufacturer: Some(Manufacturer::Winbond), - date_code: Some(ChipDateCode::YearWeek { + date_code: Some(PartDateCode::YearWeek { year: year1(&c["year"])?, week: week2(&c["week"])?, }), @@ -419,7 +108,7 @@ pub fn sharp_lh52256() -> &'static impl LabelParser { power = &c["power"], ), manufacturer: Some(Manufacturer::Sharp), - date_code: Some(ChipDateCode::YearWeek { + date_code: Some(PartDateCode::YearWeek { year: year2(&c["year"])?, week: week2(&c["week"])?, }), diff --git a/backend/src/parser/sram/sop_32.rs b/backend/src/parser/sram/sop_32.rs deleted file mode 100644 index 2158996d2..000000000 --- a/backend/src/parser/sram/sop_32.rs +++ /dev/null @@ -1,34 +0,0 @@ -use super::Ram; -use crate::{ - macros::single_parser, - parser::{week2, year2, ChipDateCode, LabelParser, Manufacturer}, -}; - -/// Hyundai HY628100 (SOP-32) -/// -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::sram::sop_32::hyundai_hy628100().parse("HYUNDAI KOREA HY628100B 0041A LLG-70").is_ok()); -/// ``` -pub fn hyundai_hy628100() -> &'static impl LabelParser { - single_parser!( - Ram, - r#"^HYUNDAI\ KOREA\ (?HY628100[AB]?)\ (?[0-9]{2})(?[0-9]{2})[A-Z]\ (?(L|LL))(?G)\-(?(50|55|70|85))$"#, - move |c| { - Ok(Ram { - kind: format!( - "{kind}{power}{package}-{speed}", - kind = &c["kind"], - power = &c["power"], - package = &c["package"], - speed = &c["speed"] - ), - manufacturer: Some(Manufacturer::Hyundai), - date_code: Some(ChipDateCode::YearWeek { - year: year2(&c["year"])?, - week: week2(&c["week"])?, - }), - }) - }, - ) -} diff --git a/backend/src/parser/sram/tsop_i_28.rs b/backend/src/parser/sram/tsop_i_28.rs index f1f90388f..e23251680 100644 --- a/backend/src/parser/sram/tsop_i_28.rs +++ b/backend/src/parser/sram/tsop_i_28.rs @@ -1,7 +1,7 @@ use super::Ram; use crate::{ macros::single_parser, - parser::{week2, year1, year2, ChipDateCode, LabelParser, Manufacturer}, + parser::{week2, year1, year2, LabelParser, Manufacturer, PartDateCode}, }; /// Sharp LH52256 @@ -24,7 +24,7 @@ pub fn sharp_lh52256() -> &'static impl LabelParser { extra = c.name("extra").map_or("", |m| m.as_str()) ), manufacturer: Some(Manufacturer::Sharp), - date_code: Some(ChipDateCode::YearWeek { + date_code: Some(PartDateCode::YearWeek { year: year2(&c["year"])?, week: week2(&c["week"])?, }), @@ -47,7 +47,7 @@ pub fn sharp_lh52cv256() -> &'static impl LabelParser { Ok(Ram { kind: c[1].to_owned(), manufacturer: Some(Manufacturer::Sharp), - date_code: Some(ChipDateCode::YearWeek { + date_code: Some(PartDateCode::YearWeek { year: year2(&c[2])?, week: week2(&c[3])?, }), @@ -71,7 +71,7 @@ pub fn sharp_lh51d256() -> &'static impl LabelParser { Ok(Ram { kind: c[1].to_owned(), manufacturer: Some(Manufacturer::Sharp), - date_code: Some(ChipDateCode::YearWeek { + date_code: Some(PartDateCode::YearWeek { year: year1(&c[3])?, week: week2(&c[4])?, }), diff --git a/backend/src/parser/sram/tsop_i_48.rs b/backend/src/parser/sram/tsop_i_48.rs deleted file mode 100644 index ba174a76c..000000000 --- a/backend/src/parser/sram/tsop_i_48.rs +++ /dev/null @@ -1,249 +0,0 @@ -// SPDX-FileCopyrightText: 2017-2023 Joonas Javanainen -// -// SPDX-License-Identifier: MIT - -use super::StaticRam; -use crate::{ - macros::single_parser, - parser::{week2, year1, year2, LabelParser, Manufacturer}, -}; - -/// NEC μPD442012A-X (TSOP-I-48) -/// -/// Source: -/// "NEC data sheet - MOS integrated circuit μPD442012A-X - 2M-bit CMOS static RAM 128k-word by 16-bit extended temperature operation" -/// -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::sram::tsop_i_48::nec_upd442012a().parse("NEC JAPAN D442012AGY-BB85X-MJH 0037K7027").is_ok()); -/// assert!(parser::sram::tsop_i_48::nec_upd442012a().parse("NEC JAPAN D442012AGY-BC85X-MJH 0330K7043").is_ok()); -/// ``` -pub fn nec_upd442012a() -> &'static impl LabelParser { - single_parser!( - StaticRam, - r#"^NEC\ JAPAN\ D442012AGY-(BB|BC|DD)([0-9]{2})X-MJH\ ([0-9]{2})([0-9]{2})[A-Z][0-9]{4}$"#, - move |c| { - Ok(StaticRam { - family: Some("μPD442012A-X"), - part: Some(format!( - "μPD442012AGY-{version}{access_time}X-MJH", - version = &c[1], - access_time = &c[2] - )), - manufacturer: Some(Manufacturer::Nec), - year: Some(year2(&c[3])?), - week: Some(week2(&c[4])?), - }) - }, - ) -} - -/// NEC μPD442012L-X (TSOP-I-48) -/// -/// Source: -/// "NEC data sheet - MOS integrated circuit μPD442012L-X - 2M-bit CMOS static RAM 128k-word by 16-bit extended temperature operation" -/// -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::sram::tsop_i_48::nec_upd442012l().parse("NEC JAPAN D442012LGY-B85X-MJH 0138K7037").is_ok()); -/// ``` -pub fn nec_upd442012l() -> &'static impl LabelParser { - single_parser!( - StaticRam, - r#"^NEC\ JAPAN\ D442012LGY-(B|C|D)([0-9]{2})X-MJH\ ([0-9]{2})([0-9]{2})[A-Z][0-9]{4}$"#, - move |c| { - Ok(StaticRam { - family: Some("μPD442012L-X"), - part: Some(format!( - "μPD442012LGY-{version}{access_time}X-MJH", - version = &c[1], - access_time = &c[2] - )), - manufacturer: Some(Manufacturer::Nec), - year: Some(year2(&c[3])?), - week: Some(week2(&c[4])?), - }) - }, - ) -} - -/// Fujitsu MB82D12160 (TSOP-I-48) -/// -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::sram::tsop_i_48::fujitsu_mb82d12160().parse("JAPAN 82D12160-10FN 0238 M88N").is_ok()); -/// ``` -pub fn fujitsu_mb82d12160() -> &'static impl LabelParser { - single_parser!( - StaticRam, - r#"^JAPAN\ 82D12160-10FN\ ([0-9]{2})([0-9]{2})\ [A-Z][0-9]{2}[A-Z]$"#, - move |c| { - Ok(StaticRam { - family: Some("MB82D12160"), - part: Some("MB82D12160-10FN".to_owned()), - manufacturer: Some(Manufacturer::Fujitsu), - year: Some(year2(&c[1])?), - week: Some(week2(&c[2])?), - }) - }, - ) -} - -/// Hynix HY62LF16206A (TSOP-I-48) -/// -/// Source: -/// "hynix HY62LF16206A-LT12C 128kx16bit full CMOS SRAM" -/// -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::sram::tsop_i_48::hynix_hy62lf16206a().parse("Hynix KOREA HY62LF16206A 0223A LT12C").is_ok()); -/// ``` -pub fn hynix_hy62lf16206a() -> &'static impl LabelParser { - single_parser!( - StaticRam, - r#"^Hynix\ KOREA\ HY62LF16206A\ ([0-9]{2})([0-9]{2})[A-Z]\ LT12C$"#, - move |c| { - Ok(StaticRam { - family: Some("HY62LF16206A"), - part: Some("HY62LF16206A-LT12C".to_owned()), - manufacturer: Some(Manufacturer::Hynix), - year: Some(year2(&c[1])?), - week: Some(week2(&c[2])?), - }) - }, - ) -} - -/// STMicro M68AS128 (TSOP-I-48) -/// -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::sram::tsop_i_48::st_micro_m68as128dl70n6().parse("M68AS128 DL70N6 AANFG F6 TWN 8B 414").is_ok()); -/// ``` -pub fn st_micro_m68as128dl70n6() -> &'static impl LabelParser { - single_parser!( - StaticRam, - r#"^([A-Z]\ )?M68AS128\ DL70N6\ [A-Z]{5}\ F6\ TWN\ [[:alnum:]]{2}\ ([0-9])([0-9]{2})$"#, - move |c| { - Ok(StaticRam { - family: Some("M68AS128"), - part: Some("M68AS128DL70N6".to_owned()), - manufacturer: Some(Manufacturer::StMicro), - year: Some(year1(&c[2])?), - week: Some(week2(&c[3])?), - }) - }, - ) -} - -/// AMIC LP62S16128BW-T (TSOP-I-48) -/// -/// Source: -/// "AMIC LP62S16128BW-T series - 128k x 16 bit low voltage CMOS SRAM" -/// -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::sram::tsop_i_48::amic_lp62s16128bw().parse("AMIC LP62S16128BW-70LLTF P4060473FB 0540A").is_ok()); -/// ``` -pub fn amic_lp62s16128bw() -> &'static impl LabelParser { - single_parser!( - StaticRam, - r#"^AMIC\ LP62S16128BW-([0-9]{2})(LLT|LLTF)\ [[:alnum:]]{10}\ ([0-9]{2})([0-9]{2})[A-Z]$"#, - move |c| { - Ok(StaticRam { - family: Some("LP62S16128BW-T"), - part: Some(format!( - "LP62S16128BW-{access_time}{version}", - access_time = &c[1], - version = &c[2], - )), - manufacturer: Some(Manufacturer::Amic), - year: Some(year2(&c[3])?), - week: Some(week2(&c[4])?), - }) - }, - ) -} - -/// BSI BS616LV2018 (TSOP-I-48) -/// -/// Source: -/// "BSI BS616LV2018 - Very Low Power/Voltage CMOS SRAM 128k x 16 bit" -/// -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::sram::tsop_i_48::bsi_bs616lv2018().parse("BSI BS616LV2018TC-70 S31686-2FY24092.1 L0314 TAIWAN").is_ok()); -/// assert!(parser::sram::tsop_i_48::bsi_bs616lv2018().parse("BSI BS616LV2018TC-70 S31686-2FY10121.1 L0230 TAIWAN").is_ok()); -/// ``` -pub fn bsi_bs616lv2018() -> &'static impl LabelParser { - single_parser!( - StaticRam, - r#"^BSI\ BS616LV2018(TC|TI)-([0-9]{2})\ S31686-2FY[0-9]{5}.1\ [A-Z]([0-9]{2})([0-9]{2})\ TAIWAN$"#, - move |c| { - Ok(StaticRam { - family: Some("BS616LV2018"), - part: Some(format!( - "BS616LV2018{version}-{access_time}", - version = &c[1], - access_time = &c[2], - )), - manufacturer: Some(Manufacturer::Bsi), - year: Some(year2(&c[3])?), - week: Some(week2(&c[4])?), - }) - }, - ) -} - -/// BSI BS616LV2019 (TSOP-I-48) -/// -/// Source: -/// "BSI BS616LV2019 - Very Low Power CMOS SRAM 128k x 16 bit" -/// -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::sram::tsop_i_48::bsi_bs616lv2019().parse("BSI BS616LV2019TC-70 S31687FZ26013.1 L0335 TAIWAN").is_ok()); -/// assert!(parser::sram::tsop_i_48::bsi_bs616lv2019().parse("BSI BS616LV2019TC-70 S31687FZ27050.1 L0336 TAIWAN").is_ok()); -/// assert!(parser::sram::tsop_i_48::bsi_bs616lv2019().parse("BSI BS616LV2019TC-70 S31687FZ31012.1 L0410 TAIWAN").is_ok()); -/// ``` -pub fn bsi_bs616lv2019() -> &'static impl LabelParser { - single_parser!( - StaticRam, - r#"^BSI\ BS616LV2019(TC|TI)-([0-9]{2})\ S31687FZ[0-9]{5}.1\ [A-Z]([0-9]{2})([0-9]{2})\ TAIWAN$"#, - move |c| { - Ok(StaticRam { - family: Some("BS616LV2019"), - part: Some(format!( - "BS616LV2019{version}-{access_time}", - version = &c[1], - access_time = &c[2], - )), - manufacturer: Some(Manufacturer::Bsi), - year: Some(year2(&c[3])?), - week: Some(week2(&c[4])?), - }) - }, - ) -} - -/// Toshiba TC55V200 (TSOP-I-48) -/// -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::sram::tsop_i_48::toshiba_tc55v200().parse("K13529 JAPAN 0106 MAD TC55V200 FT-70").is_ok()); -/// ``` -pub fn toshiba_tc55v200() -> &'static impl LabelParser { - single_parser!( - StaticRam, - r#"^K13529\ JAPAN\ ([0-9]{2})([0-9]{2})\ MAD\ TC55V200\ FT-([0-9]{2})$"#, - move |c| { - Ok(StaticRam { - family: Some("TC55V200"), - part: Some(format!("TC55V200FT-{access_time}", access_time = &c[3],)), - manufacturer: Some(Manufacturer::Toshiba), - year: Some(year2(&c[1])?), - week: Some(week2(&c[2])?), - }) - }, - ) -} diff --git a/backend/src/parser/sst.rs b/backend/src/parser/sst.rs new file mode 100644 index 000000000..ea9136dae --- /dev/null +++ b/backend/src/parser/sst.rs @@ -0,0 +1,38 @@ +// SPDX-FileCopyrightText: Joonas Javanainen +// +// SPDX-License-Identifier: MIT + +use nom::{bytes::streaming::tag, character::streaming::char, sequence::tuple, Parser as _}; + +use crate::parser::{ + for_nom::{digits, year2_week2}, + Manufacturer, NomParser, +}; + +use super::GenericPart; + +/// SST SST39VF512 (TSOP-I-32, 2.7-3.6V) +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::sst::SST_SST39VF512.parse("39VF512 70-4C-WH 0216049-D").is_ok()); +/// assert!(parser::sst::SST_SST39VF512.parse("39VF512 70-4C-WH 0350077-D").is_ok()); +/// ``` +pub static SST_SST39VF512: NomParser = NomParser { + name: "SST SST39VF512", + f: |input| { + tuple(( + tag("39VF512"), + char(' '), + tag("70-4C-WH"), // speed, durability, grade, package + char(' '), + tuple((year2_week2, digits(3), tag("-D"))), + )) + .map(|(kind, _, attrs, _, (date_code, _, _))| GenericPart { + kind: format!("SST{kind}-{attrs}"), + manufacturer: Some(Manufacturer::Sst), + date_code: Some(date_code), + }) + .parse(input) + }, +}; diff --git a/backend/src/parser/st_micro.rs b/backend/src/parser/st_micro.rs new file mode 100644 index 000000000..6278951f3 --- /dev/null +++ b/backend/src/parser/st_micro.rs @@ -0,0 +1,54 @@ +// SPDX-FileCopyrightText: Joonas Javanainen +// +// SPDX-License-Identifier: MIT + +use nom::{ + bytes::streaming::tag, + character::streaming::char, + combinator::{opt, recognize}, + sequence::tuple, + Parser as _, +}; + +use super::{ + for_nom::{alnum_uppers, uppers, year1_week2}, + GenericPart, +}; +use crate::parser::{Manufacturer, NomParser}; + +/// STMicro M68AS128 (TSOP-I-48) +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::st_micro::ST_MICRO_M68AS128.parse("M68AS128 DL70N6 AANFG F6 TWN 8B 414").is_ok()); +/// ``` +pub static ST_MICRO_M68AS128: NomParser = NomParser { + name: "STMicro M68AS128", + f: |input| { + tuple(( + opt(tag("E ")), + tag("M68AS128"), + char(' '), + recognize(tuple(( + tag("DL"), + tag("70"), // speed + tag("N"), // package + tag("6"), // temperature + ))), + char(' '), + uppers(5), + tag(" F6 TWN "), + alnum_uppers(2), + char(' '), + year1_week2, + )) + .map( + |(_, kind, _, attrs, _, _, _, _, _, date_code)| GenericPart { + kind: format!("{kind}{attrs}"), + manufacturer: Some(Manufacturer::StMicro), + date_code: Some(date_code), + }, + ) + .parse(input) + }, +}; diff --git a/backend/src/parser/supervisor_reset.rs b/backend/src/parser/supervisor_reset.rs deleted file mode 100644 index b53f9a0e9..000000000 --- a/backend/src/parser/supervisor_reset.rs +++ /dev/null @@ -1,177 +0,0 @@ -// SPDX-FileCopyrightText: 2017-2023 Joonas Javanainen -// -// SPDX-License-Identifier: MIT - -use super::{week2, year1, LabelParser, Manufacturer, ParsedData, Year}; -use crate::{ - macros::{multi_parser, single_parser}, - time::Week, -}; - -#[derive(Clone, Debug, Eq, PartialEq)] -pub struct SupervisorReset { - pub chip_type: String, - pub manufacturer: Option, - pub year: Option, - pub week: Option, -} - -impl ParsedData for SupervisorReset {} - -/// Mitsubishi M62021P -/// -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::supervisor_reset::mitsubishi_m62021p().parse("2021 7Z2").is_ok()); -/// ``` -pub fn mitsubishi_m62021p() -> &'static impl LabelParser { - single_parser!( - SupervisorReset, - r#"^2021\ ([0-9])[[:alnum:]][0-9]$"#, - move |c| { - Ok(SupervisorReset { - chip_type: "M62021P".to_owned(), - manufacturer: Some(Manufacturer::Mitsubishi), - year: Some(year1(&c[1])?), - week: None, - }) - } - ) -} - -/// Mitsumi MM1026A -/// -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::supervisor_reset::mitsumi_mm1026a().parse("843 26A").is_ok()); -/// assert!(parser::supervisor_reset::mitsumi_mm1026a().parse("1L51 26A").is_ok()); -/// ``` -pub fn mitsumi_mm1026a() -> &'static impl LabelParser { - single_parser!( - SupervisorReset, - r#"^([0-9])([[:alnum:]][0-9]{1,2})\ 26A$"#, - move |c| { - Ok(SupervisorReset { - chip_type: "MM1026A".to_owned(), - manufacturer: Some(Manufacturer::Mitsumi), - year: Some(year1(&c[1])?), - week: None, - }) - } - ) -} - -/// Mitsumi MM1134A -/// -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::supervisor_reset::mitsumi_mm1134a().parse("939 134A").is_ok()); -/// ``` -pub fn mitsumi_mm1134a() -> &'static impl LabelParser { - single_parser!(SupervisorReset, r#"^([0-9])([0-9]{2})\ 134A$"#, move |c| { - Ok(SupervisorReset { - chip_type: "MM1134A".to_owned(), - manufacturer: Some(Manufacturer::Mitsumi), - year: Some(year1(&c[1])?), - week: Some(week2(&c[2])?), - }) - }) -} - -/// ROHM BA6129 -/// -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::supervisor_reset::rohm_ba6129().parse("6129 4803").is_ok()); -/// ``` -pub fn rohm_ba6129() -> &'static impl LabelParser { - single_parser!( - SupervisorReset, - r#"^6129\ ([0-9])[[:alnum:]][0-9]{2}$"#, - move |c| { - Ok(SupervisorReset { - chip_type: "BA6129".to_owned(), - manufacturer: Some(Manufacturer::Rohm), - year: Some(year1(&c[1])?), - week: None, - }) - } - ) -} - -/// ROHM BA6129A -/// -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::supervisor_reset::rohm_ba6129a().parse("6129A 6194").is_ok()); -/// ``` -pub fn rohm_ba6129a() -> &'static impl LabelParser { - single_parser!( - SupervisorReset, - r#"^6129A\ ([0-9])[[:alnum:]][0-9]{2}$"#, - move |c| { - Ok(SupervisorReset { - chip_type: "BA6129A".to_owned(), - manufacturer: Some(Manufacturer::Rohm), - year: Some(year1(&c[1])?), - week: None, - }) - } - ) -} - -/// ROHM BA6735 -/// -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::supervisor_reset::rohm_ba6735().parse("6735 8C19").is_ok()); -/// ``` -pub fn rohm_ba6735() -> &'static impl LabelParser { - single_parser!( - SupervisorReset, - r#"^6735\ ([0-9])[[:alnum:]][0-9]{2}$"#, - move |c| { - Ok(SupervisorReset { - chip_type: "BA6735".to_owned(), - manufacturer: Some(Manufacturer::Rohm), - year: Some(year1(&c[1])?), - week: None, - }) - } - ) -} - -/// TI SN74LV2416 -/// ``` -/// use gbhwdb_backend::parser::{self, LabelParser}; -/// assert!(parser::supervisor_reset::ti_sn74lv2416().parse("LV2416 17M A23D").is_ok()); -/// assert!(parser::supervisor_reset::ti_sn74lv2416().parse("LV2416 13M A8R3").is_ok()); -/// assert!(parser::supervisor_reset::ti_sn74lv2416().parse("LV2416 0CM A73E").is_ok()); -/// ``` -pub fn ti_sn74lv2416() -> &'static impl LabelParser { - single_parser!( - SupervisorReset, - r#"^LV2416\ ([0-9])[[:alnum:]][[:alnum:]]\ [A-Z][[:alnum:]]{3}$"#, - move |c| { - Ok(SupervisorReset { - chip_type: "SN74LV2416".to_owned(), - manufacturer: Some(Manufacturer::TexasInstruments), - year: Some(year1(&c[1])?), - week: None, - }) - } - ) -} - -pub fn supervisor_reset() -> &'static impl LabelParser { - multi_parser!( - SupervisorReset, - mitsumi_mm1026a(), - mitsumi_mm1134a(), - rohm_ba6129(), - rohm_ba6129a(), - rohm_ba6735(), - mitsubishi_m62021p(), - ti_sn74lv2416(), - ) -} diff --git a/backend/src/parser/tama.rs b/backend/src/parser/tama.rs index a1b440561..7f166e676 100644 --- a/backend/src/parser/tama.rs +++ b/backend/src/parser/tama.rs @@ -3,10 +3,7 @@ // SPDX-License-Identifier: MIT use super::{week2, year2, LabelParser, ParsedData, Year}; -use crate::{ - macros::{multi_parser, single_parser}, - time::Week, -}; +use crate::{macros::single_parser, time::Week}; #[derive(Clone, Debug, Eq, PartialEq)] pub struct Tama { @@ -83,7 +80,3 @@ pub fn tama7() -> &'static impl LabelParser { }, ) } - -pub fn tama() -> &'static impl LabelParser { - multi_parser!(Tama, tama5(), tama6(), tama7()) -} diff --git a/backend/src/parser/ti.rs b/backend/src/parser/ti.rs new file mode 100644 index 000000000..667afe175 --- /dev/null +++ b/backend/src/parser/ti.rs @@ -0,0 +1,36 @@ +// SPDX-FileCopyrightText: Joonas Javanainen +// +// SPDX-License-Identifier: MIT + +use nom::{bytes::streaming::tag, character::streaming::char, sequence::tuple, Parser as _}; + +use super::{ + for_nom::{alnum_uppers, month1_123abc, year1}, + GenericPart, Manufacturer, NomParser, +}; +use crate::parser::PartDateCode; + +/// TI SN74LV2416 +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::ti::TI_SN74LV2416.parse("LV2416 17M A23D").is_ok()); +/// assert!(parser::ti::TI_SN74LV2416.parse("LV2416 13M A8R3").is_ok()); +/// assert!(parser::ti::TI_SN74LV2416.parse("LV2416 0CM A73E").is_ok()); +/// ``` +pub static TI_SN74LV2416: NomParser = NomParser { + name: "TI SN74LV2416", + f: |input| { + tuple(( + tag("LV2416 "), + tuple((year1, month1_123abc, tag("M"))), + char(' '), + tag("A").and(alnum_uppers(3)), + )) + .map(|(_, (year, month, _), _, _)| GenericPart { + kind: "SN74LV2416".to_owned(), + manufacturer: Some(Manufacturer::TexasInstruments), + date_code: Some(PartDateCode::YearMonth { year, month }), + }) + .parse(input) + }, +}; diff --git a/backend/src/parser/toshiba.rs b/backend/src/parser/toshiba.rs new file mode 100644 index 000000000..38ae4b00f --- /dev/null +++ b/backend/src/parser/toshiba.rs @@ -0,0 +1,204 @@ +// SPDX-FileCopyrightText: Joonas Javanainen +// +// SPDX-License-Identifier: MIT + +use nom::{ + branch::alt, bytes::streaming::tag, character::streaming::char, combinator::value, + error::ParseError, sequence::tuple, Parser, +}; + +use super::{ + for_nom::{cgb_rom_code, digits, dmg_rom_code, uppers, week2, year1, year2_week2}, + sram::Ram, + GenericPart, Manufacturer, MaskRom, NomParser, PartDateCode, +}; + +/// Toshiba TC8521AM (SOP-20) +/// +/// Source: +/// "TOSHIBA TC8521AP, TC8521AM (Real Time Clock II)" +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::toshiba::TOSHIBA_TC8521AM.parse("T 9722HB 8521AM").is_ok()); +/// ``` +pub static TOSHIBA_TC8521AM: NomParser = NomParser { + name: "Toshiba TC8521AM", + f: |input| toshiba_tc8521a(Package::SOP20).parse(input), +}; + +fn toshiba_tc8521a<'a, E: ParseError<&'a str>>( + package: Package, +) -> impl Parser<&'a str, GenericPart, E> { + tuple(( + tag("T "), + tuple((year2_week2, tag("HB"))), + char(' '), + tag("8521A").and(nom::character::streaming::char(package.code_char())), + )) + .map( + move |(_, (date_code, _), _, (_, package_code))| GenericPart { + kind: format!("TC8521A{package_code}"), + manufacturer: Some(Manufacturer::Toshiba), + date_code: Some(date_code), + }, + ) +} + +/// Toshiba TC7W139F +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::toshiba::TOSHIBA_TC7W139F.parse("7W139 0J").is_ok()); +/// ``` +pub static TOSHIBA_TC7W139F: NomParser = NomParser { + name: "Toshiba TC7W139F", + f: |input| { + tuple(( + alt(( + value("TC7W139FU", tag("7W139")), + value("TC7W139F", tag("7W139F")), + )), + char(' '), + year1.and(uppers(1)), + )) + .map(|(kind, _, (year, _))| GenericPart { + kind: String::from(kind), + manufacturer: Some(Manufacturer::Toshiba), + date_code: Some(PartDateCode::Year { year }), + }) + .parse(input) + }, +}; + +/// Toshiba TC74LVX04FT +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::toshiba::TOSHIBA_TC74LVX04FT.parse("LVX 04 8 45").is_ok()); +/// ``` +pub static TOSHIBA_TC74LVX04FT: NomParser = NomParser { + name: "Toshiba TC74LVX04FT", + f: |input| { + tuple((tag("LVX 04 "), year1, char(' '), week2)) + .map(|(_, year, _, week)| GenericPart { + kind: "TC74LVX04FT".to_owned(), + manufacturer: Some(Manufacturer::Toshiba), + date_code: Some(PartDateCode::YearWeek { year, week }), + }) + .parse(input) + }, +}; + +fn tc53<'a, E: ParseError<&'a str>>( + chip_type: &'static str, + unknown: &'static str, + package: Package, +) -> impl Parser<&'a str, MaskRom, E> { + tuple(( + tag("TOSHIBA "), + tuple(( + year2_week2, + tag("EAI "), + tag(chip_type), + char(package.code_char()), + )), + char(' '), + alt((dmg_rom_code(), cgb_rom_code())), + char(' '), + tag(unknown), + char(' '), + uppers(1).and(digits(3)), + tag(" JAPAN"), + )) + .map( + |(_, (date_code, _, kind, package), _, rom_id, _, _, _, _, _)| MaskRom { + rom_id: String::from(rom_id), + chip_type: Some(format!("{kind}{package}")), + manufacturer: Some(Manufacturer::Toshiba), + date_code: Some(date_code), + }, + ) +} + +/// Toshiba TC531001 (SOP-32, 4.5-5.5V) +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::toshiba::TOSHIBA_TC531001.parse("TOSHIBA 9144EAI TC531001CF DMG-FAE-0 C1 J619 JAPAN").is_ok()); +/// ``` +pub static TOSHIBA_TC531001: NomParser = NomParser { + name: "Toshiba TC531001", + f: |input| tc53("TC531001C", "C1", Package::SOP32).parse(input), +}; + +/// Toshiba TC532000 (SOP-32, 4.5-5.5V) +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::toshiba::TOSHIBA_TC532000.parse("TOSHIBA 9114EAI TC532000BF DMG-GWJ-0 D1 J542 JAPAN").is_ok()); +/// ``` +pub static TOSHIBA_TC532000: NomParser = NomParser { + name: "Toshiba TC532000", + f: |input| tc53("TC532000B", "D1", Package::SOP32).parse(input), +}; + +/// Toshiba TC534000 (SOP-32, 4.5-5.5V) +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::toshiba::TOSHIBA_TC534000.parse("TOSHIBA 9301EAI TC534000BF DMG-MQE-2 E1 N516 JAPAN").is_ok()); +/// assert!(parser::toshiba::TOSHIBA_TC534000.parse("TOSHIBA 9614EAI TC534000DF DMG-WJA-0 E1 N750 JAPAN").is_ok()); +/// ``` +pub static TOSHIBA_TC534000: NomParser = NomParser { + name: "Toshiba TC534000", + f: |input| { + alt(( + tc53("TC534000B", "E1", Package::SOP32), + tc53("TC534000D", "E1", Package::SOP32), + )) + .parse(input) + }, +}; + +/// Toshiba TC55V200 (TSOP-I-48, 2.7-3.6V) +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::toshiba::TOSHIBA_TC55V200.parse("K13529 JAPAN 0106 MAD TC55V200 FT-70").is_ok()); +/// ``` +pub static TOSHIBA_TC55V200: NomParser = NomParser { + name: "Toshiba TC55V200", + f: |input| { + tuple(( + uppers(1).and(digits(5)), + tag(" JAPAN "), + year2_week2, + tag(" MAD "), + tag("TC55V200"), + char(' '), + tag("FT-").and(alt((tag("70"), tag("85"), tag("10")))), + )) + .map(|(_, _, date_code, _, kind, _, (_, speed))| Ram { + kind: format!("{kind}FT-{speed}"), + manufacturer: Some(Manufacturer::Toshiba), + date_code: Some(date_code), + }) + .parse(input) + }, +}; + +#[derive(Copy, Clone, Debug, PartialEq, Eq)] +pub enum Package { + SOP20, + SOP32, +} + +impl Package { + pub const fn code_char(&self) -> char { + match self { + Package::SOP20 => 'M', + Package::SOP32 => 'F', + } + } +} diff --git a/backend/src/parser/victronix.rs b/backend/src/parser/victronix.rs new file mode 100644 index 000000000..6c5368a08 --- /dev/null +++ b/backend/src/parser/victronix.rs @@ -0,0 +1,34 @@ +// SPDX-FileCopyrightText: Joonas Javanainen +// +// SPDX-License-Identifier: MIT + +use nom::{bytes::streaming::tag, character::streaming::char, sequence::tuple, Parser}; + +use super::{ + for_nom::{alnum_uppers, digits, year2_week2}, + GenericPart, Manufacturer, NomParser, +}; + +/// Victronix VN4464 (SOP-28, 5V) +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::victronix::VICTRONIX_VN4464.parse("Victronix VN4464S-08LL 95103B029").is_ok()); +/// ``` +pub static VICTRONIX_VN4464: NomParser = NomParser { + name: "Victronix VN4464", + f: |input| { + tuple(( + tag("Victronix "), + tuple((tag("VN4464"), tag("S-08LL"))), + char(' '), + tuple((year2_week2, digits(1), alnum_uppers(1), digits(3))), + )) + .map(|(_, (kind, attrs), _, (date_code, _, _, _))| GenericPart { + kind: format!("{kind}{attrs}"), + manufacturer: Some(Manufacturer::Victronix), + date_code: Some(date_code), + }) + .parse(input) + }, +}; diff --git a/backend/src/parser/winbond.rs b/backend/src/parser/winbond.rs new file mode 100644 index 000000000..26bfd9781 --- /dev/null +++ b/backend/src/parser/winbond.rs @@ -0,0 +1,127 @@ +// SPDX-FileCopyrightText: Joonas Javanainen +// +// SPDX-License-Identifier: MIT + +use nom::{ + bytes::streaming::tag, character::streaming::char, combinator::value, error::ParseError, + sequence::tuple, Parser, +}; + +use super::{ + for_nom::{digits, uppers, year1_week2}, + sram::Ram, + Manufacturer, NomParser, +}; + +/// Winbond W24257 (4.5-5.5V) +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::winbond::WINBOND_W24257.parse("Winbond W24257S-70LL 046QB202858301AC").is_ok()); +/// ``` +pub static WINBOND_W24257: NomParser = NomParser { + name: "Winbond W24257", + f: |input| { + tuple(( + tag("Winbond "), + tuple(( + tag("W24257"), + package(Package::Sop28), + char('-'), + tag("70"), // speed + tag("LL"), // power + )), + char(' '), + tuple((year1_week2, uppers(2), digits(9), uppers(2))), + )) + .map( + |(_, (kind, package, _, speed, power), _, (date_code, _, _, _))| Ram { + kind: format!("{kind}{package}-{speed}{power}", package = package.code()), + manufacturer: Some(Manufacturer::Winbond), + date_code: Some(date_code), + }, + ) + .parse(input) + }, +}; + +/// Winbond W24258 (2.7-5.5V) +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::winbond::WINBOND_W24258.parse("Winbond W24258S-70LE 011MH200254401AA").is_ok()); +/// ``` +pub static WINBOND_W24258: NomParser = NomParser { + name: "Winbond W24258", + f: |input| { + tuple(( + tag("Winbond "), + tuple(( + tag("W24258"), + package(Package::Sop28), + char('-'), + tag("70"), + tag("LE"), + )), + char(' '), + tuple((year1_week2, uppers(2), digits(9), uppers(2))), + )) + .map( + |(_, (kind, package, _, speed, power), _, (date_code, _, _, _))| Ram { + kind: format!("{kind}{package}-{speed}{power}", package = package.code()), + manufacturer: Some(Manufacturer::Winbond), + date_code: Some(date_code), + }, + ) + .parse(input) + }, +}; + +/// Winbond W2465 (4.5-5.5V) +/// +/// ``` +/// use gbhwdb_backend::parser::{self, LabelParser}; +/// assert!(parser::winbond::WINBOND_W2465.parse("Winbond W2465S-70LL 140SD21331480-II1RA").is_ok()); +/// ``` +pub static WINBOND_W2465: NomParser = NomParser { + name: "Winbond W2465", + f: |input| { + tuple(( + tag("Winbond "), + tuple(( + tag("W2465"), + package(Package::Sop28), + char('-'), + tag("70"), // speed + tag("LL"), // power + )), + char(' '), + tuple((year1_week2, uppers(2), digits(8), tag("-II1RA"))), + )) + .map( + |(_, (kind, package, _, speed, power), _, (date_code, _, _, _))| Ram { + kind: format!("{kind}{package}-{speed}{power}", package = package.code()), + manufacturer: Some(Manufacturer::Winbond), + date_code: Some(date_code), + }, + ) + .parse(input) + }, +}; + +fn package<'a, E: ParseError<&'a str>>(package: Package) -> impl Parser<&'a str, Package, E> { + value(package, tag(package.code())) +} + +#[derive(Copy, Clone, Debug, PartialEq, Eq)] +enum Package { + Sop28, +} + +impl Package { + pub const fn code(&self) -> &'static str { + match self { + Package::Sop28 => "S", + } + } +} diff --git a/site/src/legacy/cartridge.rs b/site/src/legacy/cartridge.rs index fc9ec0e04..292ec7927 100644 --- a/site/src/legacy/cartridge.rs +++ b/site/src/legacy/cartridge.rs @@ -5,10 +5,7 @@ use gbhwdb_backend::{ config::cartridge::*, input::cartridge::*, - parser::{ - Accelerometer, Crystal, Eeprom, Flash, GenericChip, HexInverter, LineDecoder, Mapper, - MaskRom, Rtc, StaticRam, SupervisorReset, Tama, UnknownChip, - }, + parser::{Accelerometer, Crystal, Eeprom, GenericPart, Mapper, MaskRom, Tama, UnknownChip}, }; use std::{any::Any, collections::HashMap}; @@ -51,16 +48,10 @@ impl LegacyBoard { let part = try_process::(board.year, label, parsed) .or_else(|parsed| try_process::(board.year, label, parsed)) - .or_else(|parsed| try_process::(board.year, label, parsed)) - .or_else(|parsed| try_process::(board.year, label, parsed)) - .or_else(|parsed| try_process::(board.year, label, parsed)) + .or_else(|parsed| try_process::(board.year, label, parsed)) .or_else(|parsed| try_process::(board.year, label, parsed)) - .or_else(|parsed| try_process::(board.year, label, parsed)) .or_else(|parsed| try_process::(board.year, label, parsed)) .or_else(|parsed| try_process::(board.year, label, parsed)) - .or_else(|parsed| try_process::(board.year, label, parsed)) - .or_else(|parsed| try_process::(board.year, label, parsed)) - .or_else(|parsed| try_process::(board.year, label, parsed)) .or_else(|parsed| try_process::(board.year, label, parsed)) .or_else(|parsed| try_process::(board.year, label, parsed)) .unwrap_or_else(|_| { diff --git a/site/src/main.rs b/site/src/main.rs index 1e8f87887..e0f871b10 100644 --- a/site/src/main.rs +++ b/site/src/main.rs @@ -408,7 +408,7 @@ fn read_dmg_submissions() -> Result, Error> { let year_hint = cpu.as_ref().map(|cpu| cpu.date_code.year.unwrap_or(1996)); let work_ram = console.mainboard.u2.as_ref().map(|part| { - boxed_parser(parser::sram::sram_sop_28())(year_hint, part) + boxed_parser(parser::sram::sram_sop_28_5v())(year_hint, part) .unwrap() .unwrap_or_else(|| ProcessedPart { kind: Some("blob".to_string()), @@ -416,7 +416,7 @@ fn read_dmg_submissions() -> Result, Error> { }) }); let video_ram = console.mainboard.u3.as_ref().map(|part| { - boxed_parser(parser::sram::sram_sop_28())(year_hint, part) + boxed_parser(parser::sram::sram_sop_28_5v())(year_hint, part) .unwrap() .unwrap_or_else(|| ProcessedPart { kind: Some("blob".to_string()), @@ -424,7 +424,7 @@ fn read_dmg_submissions() -> Result, Error> { }) }); let amplifier = console.mainboard.u4.as_ref().map(|part| { - boxed_parser(parser::dmg_amp::dmg_amp())(year_hint, part) + boxed_parser(parser::dmg_amp())(year_hint, part) .unwrap() .unwrap_or_else(|| ProcessedPart { kind: Some("blob".to_string()), @@ -450,7 +450,7 @@ fn read_dmg_submissions() -> Result, Error> { }; let lcd_board = console.lcd_board.as_ref().map(|board| { - let regulator = map_part(year_hint, &board.chip, parser::dmg_reg::dmg_reg()); + let regulator = map_part(year_hint, &board.chip, parser::dmg_reg()); let lcd_panel = board .screen .as_ref() @@ -610,12 +610,12 @@ fn read_sgb_submissions() -> Result, Error> { let work_ram = map_part( year_hint, &console.mainboard.u3, - parser::sram::sram_sop_28(), + parser::sram::sram_sop_28_5v(), ); let video_ram = map_part( year_hint, &console.mainboard.u4, - parser::sram::sram_sop_28(), + parser::sram::sram_sop_28_5v(), ); let rom = map_part(year_hint, &console.mainboard.u5, parser::sgb_rom::sgb_rom()); let cic = map_part(year_hint, &console.mainboard.u6, parser::cic::cic()); @@ -689,10 +689,10 @@ fn read_mgb_submissions() -> Result, Error> { let work_ram = map_part( year_hint, &console.mainboard.u2, - parser::sram::sram_sop_28(), + parser::sram::sram_sop_28_5v(), ); - let amplifier = map_part(year_hint, &console.mainboard.u3, parser::mgb_amp::mgb_amp()); - let regulator = map_part(year_hint, &console.mainboard.u4, parser::dmg_reg::dmg_reg()); + let amplifier = map_part(year_hint, &console.mainboard.u3, parser::mgb_amp()); + let regulator = map_part(year_hint, &console.mainboard.u4, parser::dmg_reg()); let crystal = map_part( year_hint, &console.mainboard.x1, @@ -786,20 +786,16 @@ fn read_mgl_submissions() -> Result, Error> { let work_ram = map_part( year_hint, &console.mainboard.u2, - parser::sram::sram_sop_28(), + parser::sram::sram_sop_28_5v(), ); - let amplifier = map_part(year_hint, &console.mainboard.u3, parser::mgb_amp::mgb_amp()); - let regulator = map_part(year_hint, &console.mainboard.u4, parser::dmg_reg::dmg_reg()); + let amplifier = map_part(year_hint, &console.mainboard.u3, parser::mgb_amp()); + let regulator = map_part(year_hint, &console.mainboard.u4, parser::dmg_reg()); let crystal = map_part( year_hint, &console.mainboard.x1, parser::crystal_4mihz::crystal_4mihz(), ); - let t1 = map_part( - year_hint, - &console.mainboard.t1, - parser::mgl_transformer::mgl_transformer(), - ); + let t1 = map_part(year_hint, &console.mainboard.t1, parser::mgl_transformer()); let mainboard = LegacyMglMainboard { kind: console.mainboard.label.clone(), circled_letters: console.mainboard.circled_letters.clone(), @@ -886,7 +882,7 @@ fn read_sgb2_submissions() -> Result, Error> { let work_ram = map_part( year_hint, &console.mainboard.u3, - parser::sram::sram_sop_28(), + parser::sram::sram_sop_28_5v(), ); let rom = map_part(year_hint, &console.mainboard.u4, parser::sgb_rom::sgb_rom()); let cic = map_part(year_hint, &console.mainboard.u5, parser::cic::cic()); @@ -965,8 +961,8 @@ fn read_cgb_submissions() -> Result, Error> { &console.mainboard.u2, parser::sram::sram_tsop_i_28(), ); - let amplifier = map_part(year_hint, &console.mainboard.u3, parser::mgb_amp::mgb_amp()); - let regulator = map_part(year_hint, &console.mainboard.u4, parser::cgb_reg::cgb_reg()); + let amplifier = map_part(year_hint, &console.mainboard.u3, parser::mgb_amp()); + let regulator = map_part(year_hint, &console.mainboard.u4, parser::cgb_reg()); let crystal = map_part( year_hint, &console.mainboard.x1, @@ -1082,13 +1078,9 @@ fn read_agb_submissions() -> Result, Error> { &console.mainboard.u2, parser::sram::sram_tsop_i_48(), ); - let regulator = map_part(year_hint, &console.mainboard.u3, parser::agb_reg::agb_reg()); - let u4 = map_part( - year_hint, - &console.mainboard.u4, - parser::agb_pmic::agb_pmic(), - ); - let amplifier = map_part(year_hint, &console.mainboard.u6, parser::agb_amp::agb_amp()); + let regulator = map_part(year_hint, &console.mainboard.u3, parser::agb_reg()); + let u4 = map_part(year_hint, &console.mainboard.u4, parser::agb_pmic()); + let amplifier = map_part(year_hint, &console.mainboard.u6, parser::agb_amp()); let crystal = map_part( year_hint, &console.mainboard.x1, @@ -1183,18 +1175,12 @@ fn read_ags_submissions() -> Result, Error> { ); let amplifier = match console.mainboard.label.as_str() { // FIXME: Not really an amplifier - "C/AGS-CPU-30" | "C/AGT-CPU-01" => map_part( - year_hint, - &console.mainboard.u3, - parser::ags_pmic_new::ags_pmic_new(), - ), - _ => map_part(year_hint, &console.mainboard.u3, parser::agb_amp::agb_amp()), + "C/AGS-CPU-30" | "C/AGT-CPU-01" => { + map_part(year_hint, &console.mainboard.u3, parser::ags_pmic_new()) + } + _ => map_part(year_hint, &console.mainboard.u3, parser::agb_amp()), }; - let u4 = map_part( - year_hint, - &console.mainboard.u4, - parser::ags_pmic_old::ags_pmic_old(), - ); + let u4 = map_part(year_hint, &console.mainboard.u4, parser::ags_pmic_old()); let u5 = map_part( year_hint, &console.mainboard.u5, @@ -1282,8 +1268,8 @@ fn read_gbs_submissions() -> Result, Error> { parser::sram::sram_tsop_i_48(), ); let u4 = map_part(year_hint, &console.mainboard.u4, parser::gbs_dol::gbs_dol()); - let u5 = map_part(year_hint, &console.mainboard.u5, parser::gbs_reg::gbs_reg()); - let u6 = map_part(year_hint, &console.mainboard.u6, parser::gbs_reg::gbs_reg()); + let u5 = map_part(year_hint, &console.mainboard.u5, parser::gbs_reg()); + let u6 = map_part(year_hint, &console.mainboard.u6, parser::gbs_reg()); let crystal = map_part( year_hint, &console.mainboard.y1, @@ -1369,11 +1355,7 @@ fn read_oxy_submissions() -> Result, Error> { &console.mainboard.u1, parser::agb_soc_bga::agb_soc_bga(), ); - let u2 = map_part( - year_hint, - &console.mainboard.u2, - parser::oxy_pmic::oxy_pmic(), - ); + let u2 = map_part(year_hint, &console.mainboard.u2, parser::oxy_pmic()); let u4 = map_part(year_hint, &console.mainboard.u4, parser::oxy_u4::oxy_u4()); let u5 = map_part(year_hint, &console.mainboard.u5, parser::oxy_u5::oxy_u5()); let mainboard = LegacyOxyMainboard { diff --git a/site/src/process/part.rs b/site/src/process/part.rs index f681bc439..1617520e6 100644 --- a/site/src/process/part.rs +++ b/site/src/process/part.rs @@ -5,7 +5,7 @@ use anyhow::{anyhow, Error}; use gbhwdb_backend::{ input::Part, - parser::{self, ChipDateCode, LabelParser, Manufacturer}, + parser::{self, LabelParser, Manufacturer, PartDateCode}, }; use crate::{process::to_full_year, process::DateCode}; @@ -107,18 +107,6 @@ impl ParsedPart for parser::Gen2Soc { } } -impl ParsedPart for parser::StaticRam { - fn process(self, year_hint: Option, label: String) -> ProcessedPart { - ProcessedPart { - label: Some(label), - kind: self.part, - manufacturer: self.manufacturer, - date_code: DateCode::loose_year_week(year_hint, self.year, self.week), - ..ProcessedPart::default() - } - } -} - impl ParsedPart for parser::Crystal { fn process(self, year_hint: Option, label: String) -> ProcessedPart { ProcessedPart { @@ -147,17 +135,6 @@ impl ParsedPart for parser::Coil { } } -impl ParsedPart for parser::Transformer { - fn process(self, _: Option, label: String) -> ProcessedPart { - ProcessedPart { - label: Some(label), - kind: Some(self.kind), - manufacturer: self.manufacturer, - ..ProcessedPart::default() - } - } -} - impl ParsedPart for parser::SgbRom { fn process(self, year_hint: Option, label: String) -> ProcessedPart { ProcessedPart { @@ -182,24 +159,26 @@ impl ParsedPart for parser::ChipYearWeek { } } -impl ParsedPart for parser::GenericChip { +fn loose_datecode(year_hint: Option, date_code: Option) -> DateCode { + match date_code { + Some(PartDateCode::Year { year }) => DateCode::loose_year_week(year_hint, Some(year), None), + Some(PartDateCode::YearMonth { year, month }) => { + DateCode::loose_year_month(year_hint, Some(year), Some(month)) + } + Some(PartDateCode::YearWeek { year, week }) => { + DateCode::loose_year_week(year_hint, Some(year), Some(week)) + } + None => DateCode::loose_year_week(year_hint, None, None), + } +} + +impl ParsedPart for parser::GenericPart { fn process(self, year_hint: Option, label: String) -> ProcessedPart { ProcessedPart { label: Some(label), kind: Some(self.kind), manufacturer: self.manufacturer, - date_code: match self.date_code { - Some(ChipDateCode::Year { year }) => { - DateCode::loose_year_week(year_hint, Some(year), None) - } - Some(ChipDateCode::YearMonth { year, month }) => { - DateCode::loose_year_month(year_hint, Some(year), Some(month)) - } - Some(ChipDateCode::YearWeek { year, week }) => { - DateCode::loose_year_week(year_hint, Some(year), Some(week)) - } - None => DateCode::loose_year_week(year_hint, None, None), - }, + date_code: loose_datecode(year_hint, self.date_code), ..ProcessedPart::default() } } @@ -211,7 +190,7 @@ impl ParsedPart for parser::MaskRom { label: Some(label), kind: self.chip_type, manufacturer: self.manufacturer, - date_code: DateCode::loose_year_week(year_hint, self.year, self.week), + date_code: loose_datecode(year_hint, self.date_code), ..ProcessedPart::default() } } @@ -229,18 +208,6 @@ impl ParsedPart for parser::Mapper { } } -impl ParsedPart for parser::SupervisorReset { - fn process(self, year_hint: Option, label: String) -> ProcessedPart { - ProcessedPart { - label: Some(label), - kind: Some(self.chip_type), - manufacturer: self.manufacturer, - date_code: DateCode::loose_year_week(year_hint, self.year, self.week), - ..ProcessedPart::default() - } - } -} - impl ParsedPart for parser::Tama { fn process(self, year_hint: Option, label: String) -> ProcessedPart { ProcessedPart {