diff --git a/boards/genericGD32F103C4.json b/boards/genericGD32F103C4.json index d842001..76647ca 100644 --- a/boards/genericGD32F103C4.json +++ b/boards/genericGD32F103C4.json @@ -17,7 +17,8 @@ "0x0004" ] ], - "spl_sub_series": "MD" + "spl_sub_series": "MD", + "variant": "GD32F103C4_GENERIC" }, "debug": { "jlink_device": "GD32F103C4", @@ -32,7 +33,8 @@ ] }, "frameworks": [ - "spl" + "spl", + "arduino" ], "name": "GD32F103C4 (6k RAM, 16k Flash)", "upload": { diff --git a/boards/genericGD32F103C6.json b/boards/genericGD32F103C6.json index 1f7b969..faab928 100644 --- a/boards/genericGD32F103C6.json +++ b/boards/genericGD32F103C6.json @@ -17,7 +17,8 @@ "0x0004" ] ], - "spl_sub_series": "MD" + "spl_sub_series": "MD", + "variant": "GD32F103C6_GENERIC" }, "debug": { "jlink_device": "GD32F103C6", @@ -32,7 +33,8 @@ ] }, "frameworks": [ - "spl" + "spl", + "arduino" ], "name": "GD32F103C6 (10k RAM, 32k Flash)", "upload": { diff --git a/boards/genericGD32F103C8.json b/boards/genericGD32F103C8.json index 3b89ce5..004bc65 100644 --- a/boards/genericGD32F103C8.json +++ b/boards/genericGD32F103C8.json @@ -17,7 +17,8 @@ "0x0004" ] ], - "spl_sub_series": "MD" + "spl_sub_series": "MD", + "variant": "GD32F103C8_GENERIC" }, "debug": { "jlink_device": "GD32F103C8", @@ -32,7 +33,8 @@ ] }, "frameworks": [ - "spl" + "spl", + "arduino" ], "name": "GD32F103C8 (20k RAM, 64k Flash)", "upload": { diff --git a/boards/genericGD32F103CB.json b/boards/genericGD32F103CB.json index 208d5ae..b4fa4c1 100644 --- a/boards/genericGD32F103CB.json +++ b/boards/genericGD32F103CB.json @@ -17,7 +17,8 @@ "0x0004" ] ], - "spl_sub_series": "MD" + "spl_sub_series": "MD", + "variant": "GD32F103CB_GENERIC" }, "debug": { "jlink_device": "GD32F103CB", @@ -32,7 +33,8 @@ ] }, "frameworks": [ - "spl" + "spl", + "arduino" ], "name": "GD32F103CB (20k RAM, 128k Flash)", "upload": { diff --git a/boards/genericGD32F103R4.json b/boards/genericGD32F103R4.json index e84b3d4..7e9974f 100644 --- a/boards/genericGD32F103R4.json +++ b/boards/genericGD32F103R4.json @@ -17,7 +17,8 @@ "0x0004" ] ], - "spl_sub_series": "MD" + "spl_sub_series": "MD", + "variant": "GD32F103R4_GENERIC" }, "debug": { "jlink_device": "GD32F103R4", @@ -32,7 +33,8 @@ ] }, "frameworks": [ - "spl" + "spl", + "arduino" ], "name": "GD32F103R4 (6k RAM, 16k Flash)", "upload": { diff --git a/boards/genericGD32F103R6.json b/boards/genericGD32F103R6.json index 13b89db..3c24062 100644 --- a/boards/genericGD32F103R6.json +++ b/boards/genericGD32F103R6.json @@ -17,7 +17,8 @@ "0x0004" ] ], - "spl_sub_series": "MD" + "spl_sub_series": "MD", + "variant": "GD32F103R6_GENERIC" }, "debug": { "jlink_device": "GD32F103R6", @@ -32,7 +33,8 @@ ] }, "frameworks": [ - "spl" + "spl", + "arduino" ], "name": "GD32F103R6 (10k RAM, 32k Flash)", "upload": { diff --git a/boards/genericGD32F103R8.json b/boards/genericGD32F103R8.json index 95d760d..1a9ebdd 100644 --- a/boards/genericGD32F103R8.json +++ b/boards/genericGD32F103R8.json @@ -17,7 +17,8 @@ "0x0004" ] ], - "spl_sub_series": "MD" + "spl_sub_series": "MD", + "variant": "GD32F103R8_GENERIC" }, "debug": { "jlink_device": "GD32F103R8", @@ -32,7 +33,8 @@ ] }, "frameworks": [ - "spl" + "spl", + "arduino" ], "name": "GD32F103R8 (20k RAM, 64k Flash)", "upload": { diff --git a/boards/genericGD32F103RB.json b/boards/genericGD32F103RB.json index 4c623fd..0f6b35d 100644 --- a/boards/genericGD32F103RB.json +++ b/boards/genericGD32F103RB.json @@ -17,7 +17,8 @@ "0x0004" ] ], - "spl_sub_series": "MD" + "spl_sub_series": "MD", + "variant": "GD32F103RB_GENERIC" }, "debug": { "jlink_device": "GD32F103RB", @@ -32,7 +33,8 @@ ] }, "frameworks": [ - "spl" + "spl", + "arduino" ], "name": "GD32F103RB (20k RAM, 128k Flash)", "upload": { diff --git a/boards/genericGD32F103RC.json b/boards/genericGD32F103RC.json index 492b77f..6dcdccd 100644 --- a/boards/genericGD32F103RC.json +++ b/boards/genericGD32F103RC.json @@ -17,7 +17,8 @@ "0x0004" ] ], - "spl_sub_series": "HD" + "spl_sub_series": "HD", + "variant": "GD32F103RC_GENERIC" }, "debug": { "jlink_device": "GD32F103RC", @@ -32,7 +33,8 @@ ] }, "frameworks": [ - "spl" + "spl", + "arduino" ], "name": "GD32F103RC (48k RAM, 256k Flash)", "upload": { diff --git a/boards/genericGD32F103RD.json b/boards/genericGD32F103RD.json index 8a0b722..c2dcc9d 100644 --- a/boards/genericGD32F103RD.json +++ b/boards/genericGD32F103RD.json @@ -17,7 +17,8 @@ "0x0004" ] ], - "spl_sub_series": "HD" + "spl_sub_series": "HD", + "variant": "GD32F103RD_GENERIC" }, "debug": { "jlink_device": "GD32F103RD", @@ -32,7 +33,8 @@ ] }, "frameworks": [ - "spl" + "spl", + "arduino" ], "name": "GD32F103RD (64k RAM, 384k Flash)", "upload": { diff --git a/boards/genericGD32F103RE.json b/boards/genericGD32F103RE.json index 9a553dd..d06168c 100644 --- a/boards/genericGD32F103RE.json +++ b/boards/genericGD32F103RE.json @@ -17,7 +17,8 @@ "0x0004" ] ], - "spl_sub_series": "HD" + "spl_sub_series": "HD", + "variant": "GD32F103RE_GENERIC" }, "debug": { "jlink_device": "GD32F103RE", @@ -32,7 +33,8 @@ ] }, "frameworks": [ - "spl" + "spl", + "arduino" ], "name": "GD32F103RE (64k RAM, 512k Flash)", "upload": { diff --git a/boards/genericGD32F103RF.json b/boards/genericGD32F103RF.json index 6f555d9..b9c6387 100644 --- a/boards/genericGD32F103RF.json +++ b/boards/genericGD32F103RF.json @@ -17,7 +17,8 @@ "0x0004" ] ], - "spl_sub_series": "XD" + "spl_sub_series": "XD", + "variant": "GD32F103RF_GENERIC" }, "debug": { "jlink_device": "GD32F103RF", @@ -32,7 +33,8 @@ ] }, "frameworks": [ - "spl" + "spl", + "arduino" ], "name": "GD32F103RF (96k RAM, 768k Flash)", "upload": { diff --git a/boards/genericGD32F103RG.json b/boards/genericGD32F103RG.json index 48b4fe8..8a43ab0 100644 --- a/boards/genericGD32F103RG.json +++ b/boards/genericGD32F103RG.json @@ -17,7 +17,8 @@ "0x0004" ] ], - "spl_sub_series": "XD" + "spl_sub_series": "XD", + "variant": "GD32F103RG_GENERIC" }, "debug": { "jlink_device": "GD32F103RG", @@ -32,7 +33,8 @@ ] }, "frameworks": [ - "spl" + "spl", + "arduino" ], "name": "GD32F103RG (96k RAM, 1024k Flash)", "upload": { diff --git a/boards/genericGD32F103RI.json b/boards/genericGD32F103RI.json index 07499dc..0cf923e 100644 --- a/boards/genericGD32F103RI.json +++ b/boards/genericGD32F103RI.json @@ -17,7 +17,8 @@ "0x0004" ] ], - "spl_sub_series": "XD" + "spl_sub_series": "XD", + "variant": "GD32F103RI_GENERIC" }, "debug": { "jlink_device": "GD32F103RI", @@ -32,7 +33,8 @@ ] }, "frameworks": [ - "spl" + "spl", + "arduino" ], "name": "GD32F103RI (96k RAM, 2048k Flash)", "upload": { diff --git a/boards/genericGD32F103RK.json b/boards/genericGD32F103RK.json index e5bc50a..7bddf54 100644 --- a/boards/genericGD32F103RK.json +++ b/boards/genericGD32F103RK.json @@ -17,7 +17,8 @@ "0x0004" ] ], - "spl_sub_series": "XD" + "spl_sub_series": "XD", + "variant": "GD32F103RK_GENERIC" }, "debug": { "jlink_device": "GD32F103RK", @@ -32,7 +33,8 @@ ] }, "frameworks": [ - "spl" + "spl", + "arduino" ], "name": "GD32F103RK (96k RAM, 3072k Flash)", "upload": { diff --git a/boards/genericGD32F103T4.json b/boards/genericGD32F103T4.json index 316ee08..f3a17fc 100644 --- a/boards/genericGD32F103T4.json +++ b/boards/genericGD32F103T4.json @@ -17,7 +17,8 @@ "0x0004" ] ], - "spl_sub_series": "MD" + "spl_sub_series": "MD", + "variant": "GD32F103T4_GENERIC" }, "debug": { "jlink_device": "GD32F103T4", @@ -32,7 +33,8 @@ ] }, "frameworks": [ - "spl" + "spl", + "arduino" ], "name": "GD32F103T4 (6k RAM, 16k Flash)", "upload": { diff --git a/boards/genericGD32F103T6.json b/boards/genericGD32F103T6.json index 5843e12..8f5bfe5 100644 --- a/boards/genericGD32F103T6.json +++ b/boards/genericGD32F103T6.json @@ -17,7 +17,8 @@ "0x0004" ] ], - "spl_sub_series": "MD" + "spl_sub_series": "MD", + "variant": "GD32F103T6_GENERIC" }, "debug": { "jlink_device": "GD32F103T6", @@ -32,7 +33,8 @@ ] }, "frameworks": [ - "spl" + "spl", + "arduino" ], "name": "GD32F103T6 (10k RAM, 32k Flash)", "upload": { diff --git a/boards/genericGD32F103T8.json b/boards/genericGD32F103T8.json index b223f89..409d8b8 100644 --- a/boards/genericGD32F103T8.json +++ b/boards/genericGD32F103T8.json @@ -17,7 +17,8 @@ "0x0004" ] ], - "spl_sub_series": "MD" + "spl_sub_series": "MD", + "variant": "GD32F103T8_GENERIC" }, "debug": { "jlink_device": "GD32F103T8", @@ -32,7 +33,8 @@ ] }, "frameworks": [ - "spl" + "spl", + "arduino" ], "name": "GD32F103T8 (20k RAM, 64k Flash)", "upload": { diff --git a/boards/genericGD32F103TB.json b/boards/genericGD32F103TB.json index 9943bf2..3f3a069 100644 --- a/boards/genericGD32F103TB.json +++ b/boards/genericGD32F103TB.json @@ -17,7 +17,8 @@ "0x0004" ] ], - "spl_sub_series": "MD" + "spl_sub_series": "MD", + "variant": "GD32F103TB_GENERIC" }, "debug": { "jlink_device": "GD32F103TB", @@ -32,7 +33,8 @@ ] }, "frameworks": [ - "spl" + "spl", + "arduino" ], "name": "GD32F103TB (20k RAM, 128k Flash)", "upload": { diff --git a/boards/genericGD32F103V8.json b/boards/genericGD32F103V8.json index a7b5231..8920087 100644 --- a/boards/genericGD32F103V8.json +++ b/boards/genericGD32F103V8.json @@ -17,7 +17,8 @@ "0x0004" ] ], - "spl_sub_series": "MD" + "spl_sub_series": "MD", + "variant": "GD32F103V8_GENERIC" }, "debug": { "jlink_device": "GD32F103V8", @@ -32,7 +33,8 @@ ] }, "frameworks": [ - "spl" + "spl", + "arduino" ], "name": "GD32F103V8 (20k RAM, 64k Flash)", "upload": { diff --git a/boards/genericGD32F103VB.json b/boards/genericGD32F103VB.json index 4295dde..17ae7ab 100644 --- a/boards/genericGD32F103VB.json +++ b/boards/genericGD32F103VB.json @@ -17,7 +17,8 @@ "0x0004" ] ], - "spl_sub_series": "MD" + "spl_sub_series": "MD", + "variant": "GD32F103VB_GENERIC" }, "debug": { "jlink_device": "GD32F103VB", @@ -32,7 +33,8 @@ ] }, "frameworks": [ - "spl" + "spl", + "arduino" ], "name": "GD32F103VB (20k RAM, 128k Flash)", "upload": { diff --git a/boards/genericGD32F103VC.json b/boards/genericGD32F103VC.json index 0a21cb1..378ce5e 100644 --- a/boards/genericGD32F103VC.json +++ b/boards/genericGD32F103VC.json @@ -17,7 +17,8 @@ "0x0004" ] ], - "spl_sub_series": "HD" + "spl_sub_series": "HD", + "variant": "GD32F103VC_GENERIC" }, "debug": { "jlink_device": "GD32F103VC", @@ -32,7 +33,8 @@ ] }, "frameworks": [ - "spl" + "spl", + "arduino" ], "name": "GD32F103VC (48k RAM, 256k Flash)", "upload": { diff --git a/boards/genericGD32F103VD.json b/boards/genericGD32F103VD.json index ff78afd..e50f5a4 100644 --- a/boards/genericGD32F103VD.json +++ b/boards/genericGD32F103VD.json @@ -17,7 +17,8 @@ "0x0004" ] ], - "spl_sub_series": "HD" + "spl_sub_series": "HD", + "variant": "GD32F103VD_GENERIC" }, "debug": { "jlink_device": "GD32F103VD", @@ -32,7 +33,8 @@ ] }, "frameworks": [ - "spl" + "spl", + "arduino" ], "name": "GD32F103VD (64k RAM, 384k Flash)", "upload": { diff --git a/boards/genericGD32F103VE.json b/boards/genericGD32F103VE.json index eef1382..74486a7 100644 --- a/boards/genericGD32F103VE.json +++ b/boards/genericGD32F103VE.json @@ -17,7 +17,8 @@ "0x0004" ] ], - "spl_sub_series": "HD" + "spl_sub_series": "HD", + "variant": "GD32F103VE_GENERIC" }, "debug": { "jlink_device": "GD32F103VE", @@ -32,7 +33,8 @@ ] }, "frameworks": [ - "spl" + "spl", + "arduino" ], "name": "GD32F103VE (64k RAM, 512k Flash)", "upload": { diff --git a/boards/genericGD32F103VF.json b/boards/genericGD32F103VF.json index 72d8dd5..46d149c 100644 --- a/boards/genericGD32F103VF.json +++ b/boards/genericGD32F103VF.json @@ -17,7 +17,8 @@ "0x0004" ] ], - "spl_sub_series": "XD" + "spl_sub_series": "XD", + "variant": "GD32F103VF_GENERIC" }, "debug": { "jlink_device": "GD32F103VF", @@ -32,7 +33,8 @@ ] }, "frameworks": [ - "spl" + "spl", + "arduino" ], "name": "GD32F103VF (96k RAM, 768k Flash)", "upload": { diff --git a/boards/genericGD32F103VG.json b/boards/genericGD32F103VG.json index 561b2f1..030feea 100644 --- a/boards/genericGD32F103VG.json +++ b/boards/genericGD32F103VG.json @@ -17,7 +17,8 @@ "0x0004" ] ], - "spl_sub_series": "XD" + "spl_sub_series": "XD", + "variant": "GD32F103VG_GENERIC" }, "debug": { "jlink_device": "GD32F103VG", @@ -32,7 +33,8 @@ ] }, "frameworks": [ - "spl" + "spl", + "arduino" ], "name": "GD32F103VG (96k RAM, 1024k Flash)", "upload": { diff --git a/boards/genericGD32F103VI.json b/boards/genericGD32F103VI.json index 7a164ac..6c97dc7 100644 --- a/boards/genericGD32F103VI.json +++ b/boards/genericGD32F103VI.json @@ -17,7 +17,8 @@ "0x0004" ] ], - "spl_sub_series": "XD" + "spl_sub_series": "XD", + "variant": "GD32F103VI_GENERIC" }, "debug": { "jlink_device": "GD32F103VI", @@ -32,7 +33,8 @@ ] }, "frameworks": [ - "spl" + "spl", + "arduino" ], "name": "GD32F103VI (96k RAM, 2048k Flash)", "upload": { diff --git a/boards/genericGD32F103VK.json b/boards/genericGD32F103VK.json index 1efb274..7a07190 100644 --- a/boards/genericGD32F103VK.json +++ b/boards/genericGD32F103VK.json @@ -17,7 +17,8 @@ "0x0004" ] ], - "spl_sub_series": "XD" + "spl_sub_series": "XD", + "variant": "GD32F103VK_GENERIC" }, "debug": { "jlink_device": "GD32F103VK", @@ -32,7 +33,8 @@ ] }, "frameworks": [ - "spl" + "spl", + "arduino" ], "name": "GD32F103VK (96k RAM, 3072k Flash)", "upload": { diff --git a/boards/genericGD32F103ZC.json b/boards/genericGD32F103ZC.json index ad2a76a..32e2036 100644 --- a/boards/genericGD32F103ZC.json +++ b/boards/genericGD32F103ZC.json @@ -17,7 +17,8 @@ "0x0004" ] ], - "spl_sub_series": "HD" + "spl_sub_series": "HD", + "variant": "GD32F103ZC_GENERIC" }, "debug": { "jlink_device": "GD32F103ZC", @@ -32,7 +33,8 @@ ] }, "frameworks": [ - "spl" + "spl", + "arduino" ], "name": "GD32F103ZC (48k RAM, 256k Flash)", "upload": { diff --git a/boards/genericGD32F103ZD.json b/boards/genericGD32F103ZD.json index b2914ab..88270a2 100644 --- a/boards/genericGD32F103ZD.json +++ b/boards/genericGD32F103ZD.json @@ -17,7 +17,8 @@ "0x0004" ] ], - "spl_sub_series": "HD" + "spl_sub_series": "HD", + "variant": "GD32F103ZD_GENERIC" }, "debug": { "jlink_device": "GD32F103ZD", @@ -32,7 +33,8 @@ ] }, "frameworks": [ - "spl" + "spl", + "arduino" ], "name": "GD32F103ZD (64k RAM, 384k Flash)", "upload": { diff --git a/boards/genericGD32F103ZE.json b/boards/genericGD32F103ZE.json index c766886..834b484 100644 --- a/boards/genericGD32F103ZE.json +++ b/boards/genericGD32F103ZE.json @@ -17,7 +17,8 @@ "0x0004" ] ], - "spl_sub_series": "HD" + "spl_sub_series": "HD", + "variant": "GD32F103ZE_GENERIC" }, "debug": { "jlink_device": "GD32F103ZE", @@ -32,7 +33,8 @@ ] }, "frameworks": [ - "spl" + "spl", + "arduino" ], "name": "GD32F103ZE (64k RAM, 512k Flash)", "upload": { diff --git a/boards/genericGD32F103ZF.json b/boards/genericGD32F103ZF.json index 7173a10..4b74e90 100644 --- a/boards/genericGD32F103ZF.json +++ b/boards/genericGD32F103ZF.json @@ -17,7 +17,8 @@ "0x0004" ] ], - "spl_sub_series": "XD" + "spl_sub_series": "XD", + "variant": "GD32F103ZF_GENERIC" }, "debug": { "jlink_device": "GD32F103ZF", @@ -32,7 +33,8 @@ ] }, "frameworks": [ - "spl" + "spl", + "arduino" ], "name": "GD32F103ZF (96k RAM, 768k Flash)", "upload": { diff --git a/boards/genericGD32F103ZG.json b/boards/genericGD32F103ZG.json index dca6ee0..a30a068 100644 --- a/boards/genericGD32F103ZG.json +++ b/boards/genericGD32F103ZG.json @@ -17,7 +17,8 @@ "0x0004" ] ], - "spl_sub_series": "XD" + "spl_sub_series": "XD", + "variant": "GD32F103ZG_GENERIC" }, "debug": { "jlink_device": "GD32F103ZG", @@ -32,7 +33,8 @@ ] }, "frameworks": [ - "spl" + "spl", + "arduino" ], "name": "GD32F103ZG (96k RAM, 1024k Flash)", "upload": { diff --git a/boards/genericGD32F103ZI.json b/boards/genericGD32F103ZI.json index f3be08d..e149673 100644 --- a/boards/genericGD32F103ZI.json +++ b/boards/genericGD32F103ZI.json @@ -17,7 +17,8 @@ "0x0004" ] ], - "spl_sub_series": "XD" + "spl_sub_series": "XD", + "variant": "GD32F103ZI_GENERIC" }, "debug": { "jlink_device": "GD32F103ZI", @@ -32,7 +33,8 @@ ] }, "frameworks": [ - "spl" + "spl", + "arduino" ], "name": "GD32F103ZI (96k RAM, 2048k Flash)", "upload": { diff --git a/boards/genericGD32F103ZK.json b/boards/genericGD32F103ZK.json index c7d9ea3..7f0f287 100644 --- a/boards/genericGD32F103ZK.json +++ b/boards/genericGD32F103ZK.json @@ -17,7 +17,8 @@ "0x0004" ] ], - "spl_sub_series": "XD" + "spl_sub_series": "XD", + "variant": "GD32F103ZK_GENERIC" }, "debug": { "jlink_device": "GD32F103ZK", @@ -32,7 +33,8 @@ ] }, "frameworks": [ - "spl" + "spl", + "arduino" ], "name": "GD32F103ZK (96k RAM, 3072k Flash)", "upload": { diff --git a/misc/scripts/board_generator.py b/misc/scripts/board_generator.py index 1f12d91..2b02211 100644 --- a/misc/scripts/board_generator.py +++ b/misc/scripts/board_generator.py @@ -225,7 +225,7 @@ def infer_arduino_variant(self): if self.name in GD32MCUInfo.known_arduino_variants: self.arduino_variant = GD32MCUInfo.known_arduino_variants[self.name] # generated by gd32_genpinmap.py - elif any([self.name.startswith(x) for x in ["GD32F190", "GD32F170", "GD32F150", "GD32F130", "GD32F350", "GD32F330", "GD32E230"]]): + elif any([self.name.startswith(x) for x in ["GD32F103", "GD32F190", "GD32F170", "GD32F150", "GD32F130", "GD32F350", "GD32F330", "GD32E230"]]): self.arduino_variant = self.name_no_package + "_GENERIC" def infer_mbedos_variant(self): diff --git a/misc/scripts/gd32_genpinmap/datasheet_parser.py b/misc/scripts/gd32_genpinmap/datasheet_parser.py index 6b37864..b0194c9 100644 --- a/misc/scripts/gd32_genpinmap/datasheet_parser.py +++ b/misc/scripts/gd32_genpinmap/datasheet_parser.py @@ -345,7 +345,7 @@ def process_add_funcs_dataframe(dfs: DataFrame, datasheet_info: DatasheetParsing last_column = the_overwrite_quirk.pin_description add_funcs_arr = GD32DatasheetParser.analyze_additional_funcs_string(last_column) print("Pin %s Add. Funcs: %s" % (pin_name, str(add_funcs_arr))) - additional_funcs[pin_name] = GD32Pin(pin_name, [GD32PinFunction(sig, None, None, None, pages_info.subseries, pages_info.package) for sig in add_funcs_arr]) + additional_funcs[pin_name] = GD32Pin(pin_name, [GD32PinFunction(pin_name, sig, None, None, None, datasheet_info.family_type, pages_info.subseries, pages_info.package) for sig in add_funcs_arr]) print(additional_funcs) return additional_funcs @@ -385,16 +385,20 @@ def process_alts_and_remaps(dfs: DataFrame, datasheet_info: DatasheetParsingInfo remap_arr = GD32DatasheetParser.cleanup_funcs_array(remap_arr) print("Pin %s Alt. Funcs: %s Remap funcs: %s" % (pin_name, str(alternate_arr), str(remap_arr))) parsed_pins[pin_name] = GD32Pin(pin_name, [ - GD32PinFunction(GD32DatasheetParser.analyze_footnote(sig)[0], + GD32PinFunction(pin_name, + GD32DatasheetParser.analyze_footnote(sig)[0], None, GD32DatasheetParser.analyze_footnote(sig)[1], pages_info.footnotes_device_availability, + datasheet_info.family_type, pages_info.subseries, pages_info.package, False) for sig in alternate_arr ] + [ - GD32PinFunction(GD32DatasheetParser.analyze_footnote(sig)[0], + GD32PinFunction(pin_name, + GD32DatasheetParser.analyze_footnote(sig)[0], None, GD32DatasheetParser.analyze_footnote(sig)[1], pages_info.footnotes_device_availability, + datasheet_info.family_type, pages_info.subseries, pages_info.package, True) for sig in remap_arr ]) print(parsed_pins) @@ -457,7 +461,7 @@ def process_af_dataframe(dfs: DataFrame, datasheet_info: DatasheetParsingInfo, p for f in funcs: # check if we need to extra footnotes sig_name, footnote = GD32DatasheetParser.analyze_footnote(f) - af_list.append(GD32PinFunction(sig_name, get_trailing_number(af_name), footnote, pages_info.footnotes_device_availability)) + af_list.append(GD32PinFunction(pin_name, sig_name, get_trailing_number(af_name), footnote, pages_info.footnotes_device_availability, datasheet_info.family_type)) print(af_list) parser_result_pins[pin_name] = GD32Pin(pin_name, af_list) print("Parsed all %d pins." % len(parser_result_pins)) diff --git a/misc/scripts/gd32_genpinmap/func_utils.py b/misc/scripts/gd32_genpinmap/func_utils.py index 67b93dc..24892fe 100644 --- a/misc/scripts/gd32_genpinmap/func_utils.py +++ b/misc/scripts/gd32_genpinmap/func_utils.py @@ -5,7 +5,7 @@ from typing import Tuple from pin_definitions import GD32Pin, GD32PinFunction -def get_trailing_number(s): +def get_trailing_number(s:str): m = re.search(r'\d+$', s) return int(m.group()) if m else None diff --git a/misc/scripts/gd32_genpinmap/gd32_genpinmap.py b/misc/scripts/gd32_genpinmap/gd32_genpinmap.py index 43051ac..4698eab 100644 --- a/misc/scripts/gd32_genpinmap/gd32_genpinmap.py +++ b/misc/scripts/gd32_genpinmap/gd32_genpinmap.py @@ -60,17 +60,17 @@ def main_func(): #"C:\\Users\\Max\\Desktop\\gd32_dev\\gigadevice-firmware-and-docs\\GD32F30x\\GD32F303xx_Datasheet_Rev1.9.pdf" #"C:\\Users\\Max\\Desktop\\gd32_dev\\gigadevice-firmware-and-docs\\GD32E23x\\GD32E230xx_Datasheet_Rev1.4.pdf", #"C:\\Users\\Max\\Desktop\\gd32_dev\\gigadevice-firmware-and-docs\\GD32F1x0\\GD32F190xx_Datasheet_Rev2.1.pdf", - "C:\\Users\\Max\\Desktop\\gd32_dev\\gigadevice-firmware-and-docs\\GD32F1x0\\GD32F170xx_Datasheet_Rev2.1.pdf", - "C:\\Users\\Max\\Desktop\\gd32_dev\\gigadevice-firmware-and-docs\\GD32F1x0\\GD32F150xx_Datasheet_Rev3.2.pdf", - "C:\\Users\\Max\\Desktop\\gd32_dev\\gigadevice-firmware-and-docs\\GD32F1x0\\GD32F130xx_Datasheet_Rev3.4.pdf", + # "C:\\Users\\Max\\Desktop\\gd32_dev\\gigadevice-firmware-and-docs\\GD32F1x0\\GD32F170xx_Datasheet_Rev2.1.pdf", + # "C:\\Users\\Max\\Desktop\\gd32_dev\\gigadevice-firmware-and-docs\\GD32F1x0\\GD32F150xx_Datasheet_Rev3.2.pdf", + # "C:\\Users\\Max\\Desktop\\gd32_dev\\gigadevice-firmware-and-docs\\GD32F1x0\\GD32F130xx_Datasheet_Rev3.4.pdf", + "~/gd32-pdf/GD32F103xx-Datasheet-Rev-2.7.pdf" ] for datasheet_pdf_path in datasheet_pdf_paths: device_pinmap = load_pinmap(datasheet_pdf_path) - if device_pinmap is None or "--no-load-preparsed" in sys.argv or True: + if device_pinmap is None or "--no-load-preparsed" in sys.argv: device_pinmap = GD32DatasheetParser.get_pinmap_for_pdf(datasheet_pdf_path) save_pinmap(device_pinmap) - device_pinmap.solve_remapper_pins() - #return + #return all_matching_mcus = get_all_mcus_matching_pinmap(all_mcus, device_pinmap) GD32PinMapGenerator.generate_from_pinmap(device_pinmap, all_matching_mcus) if __name__ == "__main__": diff --git a/misc/scripts/gd32_genpinmap/gd32f10x_remap.py b/misc/scripts/gd32_genpinmap/gd32f10x_remap.py new file mode 100644 index 0000000..9e52f8d --- /dev/null +++ b/misc/scripts/gd32_genpinmap/gd32f10x_remap.py @@ -0,0 +1,268 @@ +from parsing_info import RemappingMacro + +remapping_info = { + "gd32f10x": { + "PA0": { + "TIMER1_CH0": [ + RemappingMacro("TIMER1_FULL_REMAP", disable=True), + RemappingMacro("TIMER1_PARTIAL_REMAP1") + ], + "TIMER1_ETI": [ + RemappingMacro("TIMER1_FULL_REMAP", disable=True), + RemappingMacro("TIMER1_PARTIAL_REMAP1") + ], + "USART1_CTS": [RemappingMacro("USART1_REMAP", disable=True, include_packages=["144", "100"])] + }, + "PA1": { + "TIMER1_CH1": [ + RemappingMacro("TIMER1_FULL_REMAP", disable=True), + RemappingMacro("TIMER1_PARTIAL_REMAP1") + ], + "USART1_RTS": [RemappingMacro("USART1_REMAP", disable=True, include_packages=["144", "100"])] + }, + "PA2": { + "TIMER1_CH2": [ + RemappingMacro("TIMER1_FULL_REMAP", disable=True), + RemappingMacro("TIMER1_PARTIAL_REMAP0") + ], + "TIMER8_CH0": [RemappingMacro("TIMER8_REMAP", disable=True, include_packages=["144", "100"], include_mcus=["GD32F103Z(F|G|I|K)"])], + "USART1_TX": [RemappingMacro("USART1_REMAP", disable=True, include_packages=["144", "100"])] + }, + "PA3": { + "TIMER1_CH3": [ + RemappingMacro("TIMER1_FULL_REMAP", disable=True), + RemappingMacro("TIMER1_PARTIAL_REMAP0") + ], + "TIMER8_CH1": [RemappingMacro("TIMER8_REMAP", disable=True, include_packages=["144", "100"], include_mcus=["GD32F103Z(F|G|I|K)"])], + "USART1_RX": [RemappingMacro("USART1_REMAP", disable=True, include_packages=["144", "100"])] + }, + "PA4": { + "USART1_CK": [RemappingMacro("USART1_REMAP", disable=True, include_packages=["144", "100"])], + "SPI0_NSS": [RemappingMacro("SPI0_REMAP", disable=True)], + "SPI2_NSS": [RemappingMacro("SPI0_REMAP")], + "I2S2_WS": [RemappingMacro("SPI0_REMAP")], + }, + "PA5": { + "SPI0_SCK": [RemappingMacro("SPI0_REMAP", disable=True)] + }, + "PA6": { + "TIMER0_BKIN": [RemappingMacro("TIMER0_PARTIAL_REMAP", include_packages=["144", "100", "64", "48"])], + "TIMER2_CH0": [RemappingMacro("TIMER2_FULL_REMAP", disable=True)], + "TIMER12_CH0": [RemappingMacro("TIMER12_REMAP", disable=True, include_packages=["144"], include_mcus=["GD32F103Z(F|G|I|K)"])], + "SPI0_MISO": [RemappingMacro("SPI0_REMAP", disable=True)] + }, + "PA7": { + "TIMER0_CH0_ON": [RemappingMacro("TIMER0_PARTIAL_REMAP", include_packages=["144", "100", "64", "48"])], + "TIMER2_CH1": [RemappingMacro("TIMER2_FULL_REMAP", disable=True)], + "TIMER13_CH0": [RemappingMacro("TIMER13_REMAP", disable=True, include_packages=["144"], include_mcus=["GD32F103Z(F|G|I|K)"])], + "SPI0_MOSI": [RemappingMacro("SPI0_REMAP", disable=True)] + }, + "PA8": { + "TIMER0_CH0": [ + RemappingMacro("TIMER0_FULL_REMAP", disable=True, include_packages=["144", "100", "64", "48"]), + RemappingMacro("TIMER0_PARTIAL_REMAP", include_packages=["144", "100", "64", "48"]) + ] + }, + "PA9": { + "TIMER0_CH1": [ + RemappingMacro("TIMER0_FULL_REMAP", disable=True, include_packages=["144", "100", "64", "48"]), + RemappingMacro("TIMER0_PARTIAL_REMAP", include_packages=["144", "100", "64", "48"]) + ], + "USART0_TX": [RemappingMacro("USART0_REMAP", disable=True)] + }, + "PA10": { + "TIMER0_CH2": [ + RemappingMacro("TIMER0_FULL_REMAP", disable=True, include_packages=["144", "100", "64", "48"]), + RemappingMacro("TIMER0_PARTIAL_REMAP", include_packages=["144", "100", "64", "48"]) + ], + "USART0_RX": [RemappingMacro("USART0_REMAP", disable=True)] + }, + "PA11": { + "TIMER0_CH3": [ + RemappingMacro("TIMER0_FULL_REMAP", disable=True, include_packages=["144", "100", "64", "48"]), + RemappingMacro("TIMER0_PARTIAL_REMAP", include_packages=["144", "100", "64", "48"]) + ], + "CAN0_RX": [RemappingMacro("CAN0_FULL_REMAP", disable=True, include_subseries=["CL"], include_packages=["144", "100", "64", "48"])], + "CAN_RX": [RemappingMacro("CAN_FULL_REMAP", disable=True, include_subseries=["MD", "HD", "XD"], include_packages=["144", "100", "64", "48"])], + }, + "PA12": { + "TIMER0_ETI": [ + RemappingMacro("TIMER0_FULL_REMAP", disable=True, include_packages=["144", "100", "64", "48"]), + RemappingMacro("TIMER0_PARTIAL_REMAP", include_packages=["144", "100", "64", "48"]) + ], + "CAN0_TX": [RemappingMacro("CAN0_FULL_REMAP", disable=True, include_subseries=["CL"], include_packages=["144", "100", "64", "48"])], + "CAN_TX": [RemappingMacro("CAN_FULL_REMAP", disable=True, include_subseries=["MD", "HD", "XD"], include_packages=["144", "100", "64", "48"])], + }, + "PA15": { + "TIMER1_CH0": [ + RemappingMacro("TIMER1_PARTIAL_REMAP0"), + RemappingMacro("TIMER1_FULL_REMAP", include_packages=["144", "100", "64", "48"]) + ], + "TIMER1_ETI": [ + RemappingMacro("TIMER1_PARTIAL_REMAP0"), + RemappingMacro("TIMER1_FULL_REMAP", include_packages=["144", "100", "64", "48"]) + ], + "SPI0_NSS": [RemappingMacro("SPI0_REMAP")], + "SPI2_NSS": [RemappingMacro("SPI0_REMAP", disable=True)], + "I2S2_WS": [RemappingMacro("SPI0_REMAP", disable=True)], + }, + + "PB0": { + "TIMER0_CH1_ON": [RemappingMacro("TIMER0_PARTIAL_REMAP", include_packages=["144", "100", "64", "48"])], + "TIMER2_CH2": [ + RemappingMacro("TIMER2_FULL_REMAP", disable=True), + RemappingMacro("TIMER2_PARTIAL_REMAP") + ] + }, + "PB1": { + "TIMER0_CH2_ON": [RemappingMacro("TIMER0_PARTIAL_REMAP", include_packages=["144", "100", "64", "48"])], + "TIMER2_CH3": [ + RemappingMacro("TIMER2_FULL_REMAP", disable=True), + RemappingMacro("TIMER2_PARTIAL_REMAP") + ] + }, + "PB3": { + "TIMER1_CH1": [ + RemappingMacro("TIMER1_PARTIAL_REMAP0"), + RemappingMacro("TIMER1_FULL_REMAP", include_packages=["144", "100", "64", "48"]) + ], + "SPI0_SCK": [RemappingMacro("SPI0_REMAP")], + "SPI2_SCK": [RemappingMacro("SPI0_REMAP", disable=True)], + "I2S2_CK": [RemappingMacro("SPI0_REMAP", disable=True)], + }, + "PB4": { + "TIMER2_CH0": [RemappingMacro("TIMER2_PARTIAL_REMAP")], + "SPI0_MISO": [RemappingMacro("SPI0_REMAP")], + "SPI2_MISO": [RemappingMacro("SPI0_REMAP", disable=True)], + }, + "PB5": { + "TIMER2_CH1": [RemappingMacro("TIMER2_PARTIAL_REMAP")], + "SPI0_MOSI": [RemappingMacro("SPI0_REMAP")], + "SPI2_MOSI": [RemappingMacro("SPI0_REMAP", disable=True)], + "I2S2_SD": [RemappingMacro("SPI0_REMAP", disable=True)], + "CAN1_RX": [RemappingMacro("CAN1_REMAP", include_subseries=["CL"], include_packages=["144", "100", "64", "48"])] + }, + "PB6": { + "TIMER3_CH0": [RemappingMacro("TIMER3_REMAP", disable=True, include_packages=["144", "100"])], + "USART0_TX": [RemappingMacro("USART0_REMAP")], + "I2C0_SCL": [RemappingMacro("I2C0_REMAP", disable=True)], + "CAN1_TX": [RemappingMacro("CAN1_REMAP", include_subseries=["CL"], include_packages=["144", "100", "64", "48"])] + }, + "PB7": { + "TIMER3_CH1": [RemappingMacro("TIMER3_REMAP", disable=True, include_packages=["144", "100"])], + "USART0_RX": [RemappingMacro("USART0_REMAP")], + "I2C0_SDA": [RemappingMacro("I2C0_REMAP", disable=True)] + }, + "PB8": { + "TIMER3_CH2": [RemappingMacro("TIMER3_REMAP", disable=True, include_packages=["144", "100"])], + "TIMER9_CH0": [RemappingMacro("TIMER9_REMAP", disable=True, include_packages=["144"], include_mcus=["GD32F103Z(F|G|I|K)"])], + "I2C0_SDA": [RemappingMacro("I2C0_REMAP")], + "CAN0_RX": [RemappingMacro("CAN0_PARTIAL_REMAP", include_subseries=["CL"], include_packages=["144", "100", "64", "48"])], + "CAN_RX": [RemappingMacro("CAN_PARTIAL_REMAP", include_subseries=["MD", "HD", "XD"], include_packages=["144", "100", "64", "48"])], + + }, + "PB9": { + "TIMER3_CH3": [RemappingMacro("TIMER3_REMAP", disable=True, include_packages=["144", "100"])], + "TIMER10_CH0": [RemappingMacro("TIMER10_REMAP", disable=True, include_packages=["144"], include_mcus=["GD32F103Z(F|G|I|K)"])], + "I2C0_SCL": [RemappingMacro("I2C0_REMAP")], + "CAN0_TX": [RemappingMacro("CAN0_PARTIAL_REMAP", include_subseries=["CL"], include_packages=["144", "100", "64", "48"])], + "CAN_TX": [RemappingMacro("CAN_PARTIAL_REMAP", include_subseries=["MD", "HD", "XD"], include_packages=["144", "100", "64", "48"])], + }, + "PB10": { + "TIMER1_CH2": [ + RemappingMacro("TIMER1_PARTIAL_REMAP1"), + RemappingMacro("TIMER1_FULL_REMAP", include_packages=["144", "100", "64", "48"]) + ], + "USART2_TX": [RemappingMacro("USART2_FULL_REMAP", disable=True, include_packages=["144", "100", "64"])] + }, + "PB11": { + "TIMER1_CH3": [ + RemappingMacro("TIMER1_PARTIAL_REMAP1"), + RemappingMacro("TIMER1_FULL_REMAP", include_packages=["144", "100", "64", "48"]) + ], + "USART2_RX": [RemappingMacro("USART2_FULL_REMAP", disable=True, include_packages=["144", "100", "64"])] + }, + "PB12": { + "TIMER0_BKIN": [RemappingMacro("TIMER0_FULL_REMAP", disable=True, include_packages=["144", "100", "64", "48"])], + "USART2_CK": [RemappingMacro("USART2_FULL_REMAP", disable=True, include_packages=["144", "100", "64"])], + "CAN1_RX": [RemappingMacro("CAN1_REMAP", disable=True, include_subseries=["CL"], include_packages=["144", "100", "64", "48"])] + }, + "PB13": { + "TIMER0_CH0_ON": [RemappingMacro("TIMER0_FULL_REMAP", disable=True, include_packages=["144", "100", "64", "48"])], + "USART2_CTS": [ + RemappingMacro("USART2_FULL_REMAP", disable=True, include_packages=["144", "100", "64"]), + RemappingMacro("USART2_PARTIAL_REMAP", include_packages=["144", "100", "64"]), + ], + "CAN1_TX": [RemappingMacro("CAN1_REMAP", disable=True, include_subseries=["CL"])] + }, + "PB14": { + "TIMER0_CH0_ON": [RemappingMacro("TIMER0_FULL_REMAP", disable=True, include_packages=["144", "100", "64", "48"])], + "USART2_RTS": [ + RemappingMacro("USART2_FULL_REMAP", disable=True, include_packages=["144", "100", "64"]), + RemappingMacro("USART2_PARTIAL_REMAP", include_packages=["144", "100", "64"]), + ] + }, + "PB15": { "TIMER0_CH0_ON": [RemappingMacro("TIMER0_FULL_REMAP", disable=True, include_packages=["144", "100", "64", "48"])] }, + + "PC6": { "TIMER2_CH0": [RemappingMacro("TIMER2_FULL_REMAP", include_packages=["144", "100", "64"])] }, + "PC7": { "TIMER2_CH1": [RemappingMacro("TIMER2_FULL_REMAP", include_packages=["144", "100", "64"])] }, + "PC8": { "TIMER2_CH2": [RemappingMacro("TIMER2_FULL_REMAP", include_packages=["144", "100", "64"])] }, + "PC9": { "TIMER2_CH3": [RemappingMacro("TIMER2_FULL_REMAP", include_packages=["144", "100", "64"])] }, + "PC10": { + "USART2_TX": [RemappingMacro("USART2_PARTIAL_REMAP", include_packages=["144", "100", "64"])], + "SPI2_SCK": [RemappingMacro("SPI0_REMAP")], + "I2S2_CK": [RemappingMacro("SPI0_REMAP")], + }, + "PC11": { + "USART2_RX": [RemappingMacro("USART2_PARTIAL_REMAP", include_packages=["144", "100", "64"])], + "SPI2_MISO": [RemappingMacro("SPI0_REMAP")], + }, + "PC12": { + "USART2_CK": [RemappingMacro("USART2_PARTIAL_REMAP", include_packages=["144", "100", "64"])], + "SPI2_MOSI": [RemappingMacro("SPI0_REMAP")], + "I2S2_SD": [RemappingMacro("SPI0_REMAP")], + }, + + "PD0": { + "CAN0_RX": [RemappingMacro("CAN0_FULL_REMAP", include_subseries=["CL"], include_packages=["144", "100", "64", "48"])], + "CAN_RX": [RemappingMacro("CAN_FULL_REMAP", include_subseries=["MD", "HD", "XD"], include_packages=["144", "100", "64", "48"])], + }, + "PD1": { + "CAN0_RX": [RemappingMacro("CAN0_FULL_REMAP", include_subseries=["CL"], include_packages=["144", "100", "64", "48"])], + "CAN_RX": [RemappingMacro("CAN_FULL_REMAP", include_subseries=["MD", "HD", "XD"], include_packages=["144", "100", "64", "48"])], + }, + "PD3": { "USART1_CTS": [RemappingMacro("USART1_REMAP", include_packages=["144", "100"])] }, + "PD4": { "USART1_RTS": [RemappingMacro("USART1_REMAP", include_packages=["144", "100"])] }, + "PD5": { "USART1_TX": [RemappingMacro("USART1_REMAP", include_packages=["144", "100"])] }, + "PD6": { "USART1_RX": [RemappingMacro("USART1_REMAP", include_packages=["144", "100"])] }, + "PD7": { "USART1_CK": [RemappingMacro("USART1_REMAP", include_packages=["144", "100"])] }, + "PD8": { "USART2_TX": [RemappingMacro("USART2_FULL_REMAP", include_packages=["144", "100"])] }, + "PD9": { "USART2_RX": [RemappingMacro("USART2_FULL_REMAP", include_packages=["144", "100"])] }, + "PD10": { "USART2_CK": [RemappingMacro("USART2_FULL_REMAP", include_packages=["144", "100"])] }, + "PD11": { "USART2_CTS": [RemappingMacro("USART2_FULL_REMAP", include_packages=["144", "100"])] }, + "PD12": { + "TIMER3_CH0": [RemappingMacro("TIMER3_REMAP", include_packages=["144", "100"])], + "USART2_RTS": [RemappingMacro("USART2_FULL_REMAP", include_packages=["144", "100"])] + }, + "PD13": { "TIMER3_CH1": [RemappingMacro("TIMER3_REMAP", include_packages=["144", "100"])] }, + "PD14": { "TIMER3_CH2": [RemappingMacro("TIMER3_REMAP", include_packages=["144", "100"])] }, + "PD15": { "TIMER3_CH3": [RemappingMacro("TIMER3_REMAP", include_packages=["144", "100"])] }, + + "PE5": { "TIMER8_CH0": [RemappingMacro("TIMER8_REMAP", include_packages=["144", "100"], include_mcus=["GD32F103Z(F|G|I|K)"])] }, + "PE6": { "TIMER8_CH1": [RemappingMacro("TIMER8_REMAP", include_packages=["144", "100"], include_mcus=["GD32F103Z(F|G|I|K)"])] }, + "PE7": { "TIMER0_ETI": [RemappingMacro("TIMER0_FULL_REMAP", include_packages=["144", "100"])] }, + "PE8": { "TIMER0_CH0_ON": [RemappingMacro("TIMER0_FULL_REMAP", include_packages=["144", "100"])] }, + "PE9": { "TIMER0_CH0": [RemappingMacro("TIMER0_FULL_REMAP", include_packages=["144", "100"])] }, + "PE10": { "TIMER0_CH1_ON": [RemappingMacro("TIMER0_FULL_REMAP", include_packages=["144", "100"])] }, + "PE11": { "TIMER0_CH1": [RemappingMacro("TIMER0_FULL_REMAP", include_packages=["144", "100"])] }, + "PE12": { "TIMER0_CH2_ON": [RemappingMacro("TIMER0_FULL_REMAP", include_packages=["144", "100"])] }, + "PE13": { "TIMER0_CH2": [RemappingMacro("TIMER0_FULL_REMAP", include_packages=["144", "100"])] }, + "PE14": { "TIMER0_CH3": [RemappingMacro("TIMER0_FULL_REMAP", include_packages=["144", "100"])] }, + "PE15": { "TIMER0_BKIN": [RemappingMacro("TIMER0_FULL_REMAP", include_packages=["144", "100"])] }, + + "PF6": { "TIMER9_CH0": [RemappingMacro("TIMER9_REMAP", include_packages=["144"], include_mcus=["GD32F103Z(F|G|I|K)"])] }, + "PF7": { "TIMER10_CH0": [RemappingMacro("TIMER10_REMAP", include_packages=["144"], include_mcus=["GD32F103Z(F|G|I|K)"])] }, + "PF8": { "TIMER12_CH0": [RemappingMacro("TIMER12_REMAP", include_packages=["144"], include_mcus=["GD32F103Z(F|G|I|K)"])] }, + "PF9": { "TIMER13_CH0": [RemappingMacro("TIMER13_REMAP", include_packages=["144"], include_mcus=["GD32F103Z(F|G|I|K)"])] }, + } +} \ No newline at end of file diff --git a/misc/scripts/gd32_genpinmap/known_datasheets.py b/misc/scripts/gd32_genpinmap/known_datasheets.py index 08c8adb..66e2ab9 100644 --- a/misc/scripts/gd32_genpinmap/known_datasheets.py +++ b/misc/scripts/gd32_genpinmap/known_datasheets.py @@ -1,7 +1,8 @@ from os import path from typing import Dict -from parsing_info import DatasheetAFPageParsingInfo, DatasheetPinDefPageParsingInfo, DatasheetParsingInfo +from parsing_info import DatasheetAFPageParsingInfo, DatasheetPinDefPageParsingInfo, DatasheetParsingInfo, FootnoteAvailabilityInfo from parsing_quirks import ParseUsingAreaQuirk, OverwritePinDescriptionQuirk, OverwritePinAlternateInfoQuirk, OverwriteAdditionFunctionsList, CondenseColumnsQuirk +import gd32f10x_remap # Use this info to recognize the PDF and its parsing quirks. # Every PDF will probably need different parsing quirks, like only @@ -11,9 +12,9 @@ known_datasheets_infos: Dict[str, DatasheetAFPageParsingInfo] = { "GD32F190xx_Datasheet_Rev2.1.pdf" : DatasheetParsingInfo( alternate_funcs = [ - DatasheetAFPageParsingInfo([28,29], { "1": ["GD32F190x4"], "2": ["GD32F190x8", "GD32F190x6"], "3": ["GD32F190x8"]}), - DatasheetAFPageParsingInfo([30,31], { "1": ["GD32F190x4"], "2": ["GD32F190x8", "GD32F190x6"], "3": ["GD32F190x8"]}), - DatasheetAFPageParsingInfo([32], { "1": ["GD32F190x4"], "2": ["GD32F190x8"]}, quirks=[ + DatasheetAFPageParsingInfo([28,29], { "1": FootnoteAvailabilityInfo(["GD32F190x4"]), "2": FootnoteAvailabilityInfo(["GD32F190x8", "GD32F190x6"]), "3": FootnoteAvailabilityInfo(["GD32F190x8"])}), + DatasheetAFPageParsingInfo([30,31], { "1": FootnoteAvailabilityInfo(["GD32F190x4"]), "2": FootnoteAvailabilityInfo(["GD32F190x8", "GD32F190x6"]), "3": FootnoteAvailabilityInfo(["GD32F190x8"])}), + DatasheetAFPageParsingInfo([32], { "1": FootnoteAvailabilityInfo(["GD32F190x4"]), "2": FootnoteAvailabilityInfo(["GD32F190x8"])}, quirks=[ ParseUsingAreaQuirk((95.623,123.157,766.102,533.928)), OverwritePinAlternateInfoQuirk("PF7", ["I2C0_SDA(1)/I2C1_SDA(2)", None, None, None, None, None, None, None, None, "SEG31"]) ]) @@ -48,9 +49,9 @@ ), "GD32F170xx_Datasheet_Rev2.1.pdf" : DatasheetParsingInfo( alternate_funcs = [ - DatasheetAFPageParsingInfo([26], { "1": ["GD32F170x4"], "2": ["GD32F170x8", "GD32F170x6"], "3": ["GD32F170x8"]}), - DatasheetAFPageParsingInfo([27], { "1": ["GD32F170x4"], "2": ["GD32F170x8", "GD32F170x6"], "3": ["GD32F170x8"]}), - DatasheetAFPageParsingInfo([28], { "1": ["GD32F170x4"], "2": ["GD32F170x8"]}, quirks=[ + DatasheetAFPageParsingInfo([26], { "1": FootnoteAvailabilityInfo(["GD32F170x4"]), "2": FootnoteAvailabilityInfo(["GD32F170x8", "GD32F170x6"]), "3": FootnoteAvailabilityInfo(["GD32F170x8"])}), + DatasheetAFPageParsingInfo([27], { "1": FootnoteAvailabilityInfo(["GD32F170x4"]), "2": FootnoteAvailabilityInfo(["GD32F170x8", "GD32F170x6"]), "3": FootnoteAvailabilityInfo(["GD32F170x8"])}), + DatasheetAFPageParsingInfo([28], { "1": FootnoteAvailabilityInfo(["GD32F170x4"]), "2": FootnoteAvailabilityInfo(["GD32F170x8"])}, quirks=[ OverwriteAdditionFunctionsList(["AF%d" % x for x in range(10)]) ]) ], @@ -84,20 +85,20 @@ ), "GD32F150xx_Datasheet_Rev3.2.pdf" : DatasheetParsingInfo( alternate_funcs = [ - DatasheetAFPageParsingInfo([30], { "1": ["GD32F150x4"], "2": ["GD32F150x8", "GD32F150x6"], "3": ["GD32F150x8"]}, quirks=[ + DatasheetAFPageParsingInfo([30], { "1": FootnoteAvailabilityInfo(["GD32F150x4"]), "2": FootnoteAvailabilityInfo(["GD32F150x8", "GD32F150x6"]), "3": FootnoteAvailabilityInfo(["GD32F150x8"])}, quirks=[ ParseUsingAreaQuirk((132.804,123.132,765.204,532.332)), CondenseColumnsQuirk(), OverwritePinAlternateInfoQuirk("PA11", ["EVENTOUT", "USART0_CTS", "TIMER0_CH3", "TSI_G3_CH3", None, None, None, "CMP0_OUT"]) ]), - DatasheetAFPageParsingInfo([31], { "1": ["GD32F150x4"], "2": ["GD32F150x8", "GD32F150x6"], "3": ["GD32F150x8"]}, quirks=[ + DatasheetAFPageParsingInfo([31], { "1": FootnoteAvailabilityInfo(["GD32F150x4"]), "2": FootnoteAvailabilityInfo(["GD32F150x8", "GD32F150x6"]), "3": FootnoteAvailabilityInfo(["GD32F150x8"])}, quirks=[ ParseUsingAreaQuirk((80.724,123.132,321.036,532.332)), CondenseColumnsQuirk() ]), - DatasheetAFPageParsingInfo([32], { "1": ["GD32F150x4"], "2": ["GD32F150x8", "GD32F150x6"], "3": ["GD32F150x8"]}, quirks=[ + DatasheetAFPageParsingInfo([32], { "1": FootnoteAvailabilityInfo(["GD32F150x4"]), "2": FootnoteAvailabilityInfo(["GD32F150x8", "GD32F150x6"]), "3": FootnoteAvailabilityInfo(["GD32F150x8"])}, quirks=[ ParseUsingAreaQuirk((97.836,122.388,656.58,532.332)), CondenseColumnsQuirk() ]), - DatasheetAFPageParsingInfo([33], { "1": ["GD32F150x4"], "2": ["GD32F150x8", "GD32F150x6"], "3": ["GD32F150x8"]}, quirks=[ + DatasheetAFPageParsingInfo([33], { "1": FootnoteAvailabilityInfo(["GD32F150x4"]), "2": FootnoteAvailabilityInfo(["GD32F150x8", "GD32F150x6"]), "3": FootnoteAvailabilityInfo(["GD32F150x8"])}, quirks=[ ParseUsingAreaQuirk((97.092,123.132,389.484,530.844)), CondenseColumnsQuirk() ]) @@ -193,15 +194,15 @@ ), "GD32F130xx_Datasheet_Rev3.4.pdf" : DatasheetParsingInfo( alternate_funcs = [ - DatasheetAFPageParsingInfo([31], { "1": ["GD32F130x4"], "2": ["GD32F130x8", "GD32F130x6"], "3": ["GD32F130x8"]}, quirks=[ + DatasheetAFPageParsingInfo([31], { "1": FootnoteAvailabilityInfo(["GD32F130x4"]), "2": FootnoteAvailabilityInfo(["GD32F130x8", "GD32F130x6"]), "3": FootnoteAvailabilityInfo(["GD32F130x8"])}, quirks=[ ParseUsingAreaQuirk((130.572,123.132,704.94,533.076)), CondenseColumnsQuirk(), ]), - DatasheetAFPageParsingInfo([32], { "1": ["GD32F130x4"], "2": ["GD32F130x8", "GD32F130x6"], "3": ["GD32F130x8"]}, quirks=[ + DatasheetAFPageParsingInfo([32], { "1": FootnoteAvailabilityInfo(["GD32F130x4"]), "2": FootnoteAvailabilityInfo(["GD32F130x8", "GD32F130x6"]), "3": FootnoteAvailabilityInfo(["GD32F130x8"])}, quirks=[ ParseUsingAreaQuirk((97.836,124.62,687.084,533.82)), CondenseColumnsQuirk(), ]), - DatasheetAFPageParsingInfo([33], { "1": ["GD32F130x4", "GD32F130x6"], "2": ["GD32F130x8"]}, quirks=[ + DatasheetAFPageParsingInfo([33], { "1": FootnoteAvailabilityInfo(["GD32F130x4", "GD32F130x6"]), "2": FootnoteAvailabilityInfo(["GD32F130x8"])}, quirks=[ ParseUsingAreaQuirk((96.348,124.62,405.852,533.82)), CondenseColumnsQuirk(), ]), @@ -291,17 +292,17 @@ ), "GD32E230xx_Datasheet_Rev1.4.pdf" : DatasheetParsingInfo( alternate_funcs = [ - DatasheetAFPageParsingInfo([32], { "1": ["GD32E230x4"], "2": ["GD32E230x8", "GD32E230x6"], "3": ["GD32E230x8"]}, quirks=[ + DatasheetAFPageParsingInfo([32], { "1": FootnoteAvailabilityInfo(["GD32E230x4"]), "2": FootnoteAvailabilityInfo(["GD32E230x8", "GD32E230x6"]), "3": FootnoteAvailabilityInfo(["GD32E230x8"])}, quirks=[ ParseUsingAreaQuirk((132.831,124.645,708.059,533.928)), ]), - DatasheetAFPageParsingInfo([33], { "1": ["GD32E230x4"], "2": ["GD32E230x8", "GD32E230x6"], "3": ["GD32E230x8"]}, quirks=[ + DatasheetAFPageParsingInfo([33], { "1": FootnoteAvailabilityInfo(["GD32E230x4"]), "2": FootnoteAvailabilityInfo(["GD32E230x8", "GD32E230x6"]), "3": FootnoteAvailabilityInfo(["GD32E230x8"])}, quirks=[ ParseUsingAreaQuirk((94.879,124.645,637.364,535.416)), ]), - DatasheetAFPageParsingInfo([33], { "1": ["GD32E230x4"], "2": ["GD32E230x8", "GD32E230x6"], "3": ["GD32E230x8"]}, quirks=[ + DatasheetAFPageParsingInfo([33], { "1": FootnoteAvailabilityInfo(["GD32E230x4"]), "2": FootnoteAvailabilityInfo(["GD32E230x8", "GD32E230x6"]), "3": FootnoteAvailabilityInfo(["GD32E230x8"])}, quirks=[ ParseUsingAreaQuirk((658.201,125.389,757.917,533.928 )), OverwritePinAlternateInfoQuirk("PF6", ["I2C0_SCL(1)/I2C1_SCL(3)", None, None, None, None, None, None]) ]), - DatasheetAFPageParsingInfo([34], { "1": ["GD32E230x4"], "2": ["GD32E230x8", "GD32E230x6"], "3": ["GD32E230x8"]}, quirks=[ + DatasheetAFPageParsingInfo([34], { "1": FootnoteAvailabilityInfo(["GD32E230x4"]), "2": FootnoteAvailabilityInfo(["GD32E230x8", "GD32E230x6"]), "3": FootnoteAvailabilityInfo(["GD32E230x8"])}, quirks=[ ParseUsingAreaQuirk((79.996,124.645,178.968,533.183 )) ]), ], @@ -347,19 +348,19 @@ ), "GD32F350xx_Datasheet_Rev2.3.pdf": DatasheetParsingInfo( alternate_funcs = [ - DatasheetAFPageParsingInfo([30], { "1": ["GD32F350x4"], "2": ["GD32F350xB", "GD32F350x8", "GD32F350x6"], "3": ["GD32F350xB", "GD32F350x8"]}, quirks=[ + DatasheetAFPageParsingInfo([30], { "1": FootnoteAvailabilityInfo(["GD32F350x4"]), "2": FootnoteAvailabilityInfo(["GD32F350xB", "GD32F350x8", "GD32F350x6"]), "3": FootnoteAvailabilityInfo(["GD32F350xB", "GD32F350x8"])}, quirks=[ ParseUsingAreaQuirk((127.622,122.413,748.243,535.416)), ]), - DatasheetAFPageParsingInfo([31], { "1": ["GD32F350x4"], "2": ["GD32F350xB", "GD32F350x8", "GD32F350x6"], "3": ["GD32F350xB", "GD32F350x8"]}, quirks=[ + DatasheetAFPageParsingInfo([31], { "1": FootnoteAvailabilityInfo(["GD32F350x4"]), "2": FootnoteAvailabilityInfo(["GD32F350xB", "GD32F350x8", "GD32F350x6"]), "3": FootnoteAvailabilityInfo(["GD32F350xB", "GD32F350x8"])}, quirks=[ ParseUsingAreaQuirk((97.112,117.204,687.223,539.137)), ]), - DatasheetAFPageParsingInfo([32], { "1": ["GD32F350x4"], "2": ["GD32F350xB", "GD32F350x8", "GD32F350x6"], "3": ["GD32F350xB", "GD32F350x8"]}, quirks=[ + DatasheetAFPageParsingInfo([32], { "1": FootnoteAvailabilityInfo(["GD32F350x4"]), "2": FootnoteAvailabilityInfo(["GD32F350xB", "GD32F350x8", "GD32F350x6"]), "3": FootnoteAvailabilityInfo(["GD32F350xB", "GD32F350x8"])}, quirks=[ ParseUsingAreaQuirk((97.112,124.645,394.027,534.672)), ]), - DatasheetAFPageParsingInfo([32], { "1": ["GD32F350x4"], "2": ["GD32F350xB", "GD32F350x8", "GD32F350x6"], "3": ["GD32F350xB", "GD32F350x8"]}, quirks=[ + DatasheetAFPageParsingInfo([32], { "1": FootnoteAvailabilityInfo(["GD32F350x4"]), "2": FootnoteAvailabilityInfo(["GD32F350xB", "GD32F350x8", "GD32F350x6"]), "3": FootnoteAvailabilityInfo(["GD32F350xB", "GD32F350x8"])}, quirks=[ ParseUsingAreaQuirk((431.979,116.459,728.151,555.508)), ]), - DatasheetAFPageParsingInfo([33], { "1": ["GD32F350x4"], "2": ["GD32F350xB", "GD32F350x8", "GD32F350x6"], "3": ["GD32F350xB", "GD32F350x8"]}, quirks=[ + DatasheetAFPageParsingInfo([33], { "1": FootnoteAvailabilityInfo(["GD32F350x4"]), "2": FootnoteAvailabilityInfo(["GD32F350xB", "GD32F350x8", "GD32F350x6"]), "3": FootnoteAvailabilityInfo(["GD32F350xB", "GD32F350x8"])}, quirks=[ ParseUsingAreaQuirk((97.112,123.901,422.305,534.672)), ]), ], @@ -398,19 +399,19 @@ ), "GD32F330xx_Datasheet_Rev2.6.pdf": DatasheetParsingInfo( alternate_funcs = [ - DatasheetAFPageParsingInfo([34], { "1": ["GD32F330x4"], "2": ["GD32F330xB", "GD32F330x8", "GD32F330x6"], "3": ["GD32F330xB", "GD32F330x8"]}, quirks=[ + DatasheetAFPageParsingInfo([34], { "1": FootnoteAvailabilityInfo(["GD32F330x4"]), "2": FootnoteAvailabilityInfo(["GD32F330xB", "GD32F330x8", "GD32F330x6"]), "3": FootnoteAvailabilityInfo(["GD32F330xB", "GD32F330x8"])}, quirks=[ ParseUsingAreaQuirk((125.389,124.645,643.318,536.16)), ]), - DatasheetAFPageParsingInfo([35], { "1": ["GD32F330x4"], "2": ["GD32F330xB", "GD32F330x8", "GD32F330x6"], "3": ["GD32F330xB", "GD32F330x8"]}, quirks=[ + DatasheetAFPageParsingInfo([35], { "1": FootnoteAvailabilityInfo(["GD32F330x4"]), "2": FootnoteAvailabilityInfo(["GD32F330xB", "GD32F330x8", "GD32F330x6"]), "3": FootnoteAvailabilityInfo(["GD32F330xB", "GD32F330x8"])}, quirks=[ ParseUsingAreaQuirk((94.879,125.389,562.205,534.672)), ]), - DatasheetAFPageParsingInfo([36], { "1": ["GD32F330x4"], "2": ["GD32F330xB", "GD32F330x8", "GD32F330x6"], "3": ["GD32F330xB", "GD32F330x8"]}, quirks=[ + DatasheetAFPageParsingInfo([36], { "1": FootnoteAvailabilityInfo(["GD32F330x4"]), "2": FootnoteAvailabilityInfo(["GD32F330xB", "GD32F330x8", "GD32F330x6"]), "3": FootnoteAvailabilityInfo(["GD32F330xB", "GD32F330x8"])}, quirks=[ ParseUsingAreaQuirk((110.506,123.157,405.934,533.928)), ]), - DatasheetAFPageParsingInfo([36], { "1": ["GD32F330x4"], "2": ["GD32F330xB", "GD32F330x8", "GD32F330x6"], "3": ["GD32F330xB", "GD32F330x8"]}, quirks=[ + DatasheetAFPageParsingInfo([36], { "1": FootnoteAvailabilityInfo(["GD32F330x4"]), "2": FootnoteAvailabilityInfo(["GD32F330xB", "GD32F330x8", "GD32F330x6"]), "3": FootnoteAvailabilityInfo(["GD32F330xB", "GD32F330x8"])}, quirks=[ ParseUsingAreaQuirk((442.397,118.692,729.639,539.137)), ]), - DatasheetAFPageParsingInfo([37], { "1": ["GD32F330x4"], "2": ["GD32F330xB", "GD32F330x8", "GD32F330x6"], "3": ["GD32F330xB", "GD32F330x8"]}, quirks=[ + DatasheetAFPageParsingInfo([37], { "1": FootnoteAvailabilityInfo(["GD32F330x4"]), "2": FootnoteAvailabilityInfo(["GD32F330xB", "GD32F330x8", "GD32F330x6"]), "3": FootnoteAvailabilityInfo(["GD32F330xB", "GD32F330x8"])}, quirks=[ ParseUsingAreaQuirk((111.25,123.901,436.444,535.416)), ]), ], @@ -449,6 +450,100 @@ series = "GD32F330", # series family_type = "B" # family type ), + "GD32F103xx-Datasheet-Rev-2.7.pdf": DatasheetParsingInfo( + alternate_funcs = [], + pin_defs = [ + # GD32F103Zx + DatasheetPinDefPageParsingInfo([21], "GD32F103Zx", "LQFP144", [ + ParseUsingAreaQuirk((180,123,769,527)), + OverwritePinDescriptionQuirk("PF6", "Default: PF6\rAlternate: ADC2_IN4, EXMC_NIORD\nRemap: TIMER9_CH0(3)"), + ], { "3": FootnoteAvailabilityInfo(["GD32F103Z[FGIK]"]) }), + DatasheetPinDefPageParsingInfo([22], "GD32F103Zx", "LQFP144", [ + ParseUsingAreaQuirk((88,123,769,527)), + ], { "3": FootnoteAvailabilityInfo(["GD32F103Z[FGIK]"]) }), + DatasheetPinDefPageParsingInfo([23], "GD32F103Zx", "LQFP144", [ + ParseUsingAreaQuirk((88,123,769,527)), + OverwritePinDescriptionQuirk("PG1", "Default: PG1\rAlternate: EXMC_A11"), + ], { "3": FootnoteAvailabilityInfo(["GD32F103Z[FGIK]"]) }), + DatasheetPinDefPageParsingInfo([24], "GD32F103Zx", "LQFP144", [ + ParseUsingAreaQuirk((88,123,769,527)), + OverwritePinDescriptionQuirk("PB13", "Default: PB13\rAlternate: SPI1_SCK, USART2_CTS, TIMER0_CH0_ON, I2S1_CK"), + ], { "3": FootnoteAvailabilityInfo(["GD32F103Z[FGIK]"]) }), + DatasheetPinDefPageParsingInfo([25], "GD32F103Zx", "LQFP144", [ + ParseUsingAreaQuirk((88,123,769,527)), + ], { "3": FootnoteAvailabilityInfo(["GD32F103Z[FGIK]"]) }), + DatasheetPinDefPageParsingInfo([26], "GD32F103Zx", "LQFP144", [ + ParseUsingAreaQuirk((88,123,769,527)), + OverwritePinDescriptionQuirk("PC10", "Default: PC10\nAlternate: UART3_TX, SDIO_D2\nRemap: USART2_TX, SPI2_SCK, I2S2_CK"), + ], { "3": FootnoteAvailabilityInfo(["GD32F103Z[FGIK]"]) }), + DatasheetPinDefPageParsingInfo([27], "GD32F103Zx", "LQFP144", [ + ParseUsingAreaQuirk((88,123,769,527)), + ], { "3": FootnoteAvailabilityInfo(["GD32F103Z[FGIK]"]) }), + DatasheetPinDefPageParsingInfo([28], "GD32F103Zx", "LQFP144", [ + ParseUsingAreaQuirk((88,123,650,527)), + ], { "3": FootnoteAvailabilityInfo(["GD32F103Z[FGIK]"]) }), + # GD32F103Vx + DatasheetPinDefPageParsingInfo([29], "GD32F103Vx", "LQFP100", [ + ParseUsingAreaQuirk((133,123,769,527)), + ], { "3": FootnoteAvailabilityInfo(["GD32F103V[FGIK]"]), "4": FootnoteAvailabilityInfo(["GD32F103V[CDEFGIK]"]), "5": FootnoteAvailabilityInfo(["GD32F103V[CDEFGIK]"], "ADC2") }), + DatasheetPinDefPageParsingInfo([30], "GD32F103Vx", "LQFP100", [ + ParseUsingAreaQuirk((88,123,769,527)), + ], { "3": FootnoteAvailabilityInfo(["GD32F103V[FGIK]"]), "4": FootnoteAvailabilityInfo(["GD32F103V[CDEFGIK]"]), "5": FootnoteAvailabilityInfo(["GD32F103V[CDEFGIK]"], "ADC2") }), + DatasheetPinDefPageParsingInfo([31], "GD32F103Vx", "LQFP100", [ + ParseUsingAreaQuirk((88,123,769,527)), + OverwritePinDescriptionQuirk("PB13", "Default: PB13\nAlternate: SPI1_SCK, USART2_CTS, TIMER0_CH0_ON, I2S1_CK(4)"), + ], { "3": FootnoteAvailabilityInfo(["GD32F103V[FGIK]"]), "4": FootnoteAvailabilityInfo(["GD32F103V[CDEFGIK]"]), "5": FootnoteAvailabilityInfo(["GD32F103V[CDEFGIK]"], "ADC2") }), + DatasheetPinDefPageParsingInfo([32], "GD32F103Vx", "LQFP100", [ + ParseUsingAreaQuirk((88,123,769,527)), + OverwritePinDescriptionQuirk("PC9", "Default: PB13\nAlternate: TIMER7_CH3(4), SDIO_D1(4)\nRemap: TIMER2_CH3"), + ], { "3": FootnoteAvailabilityInfo(["GD32F103V[FGIK]"]), "4": FootnoteAvailabilityInfo(["GD32F103V[CDEFGIK]"]), "5": FootnoteAvailabilityInfo(["GD32F103V[CDEFGIK]"], "ADC2") }), + DatasheetPinDefPageParsingInfo([33], "GD32F103Vx", "LQFP100", [ + ParseUsingAreaQuirk((88,123,769,527)), + OverwritePinDescriptionQuirk("PD3", "Default: PD3\nAlternate: EXMC_CLK\nRemap: USART1_CTS"), + ], { "3": FootnoteAvailabilityInfo(["GD32F103V[FGIK]"]), "4": FootnoteAvailabilityInfo(["GD32F103V[CDEFGIK]"]), "5": FootnoteAvailabilityInfo(["GD32F103V[CDEFGIK]"], "ADC2") }), + # GD32F103Rx + DatasheetPinDefPageParsingInfo([36], "GD32F103Rx", "LQFP64", [ + ParseUsingAreaQuirk((135,123,769,527)), + ], { "3": FootnoteAvailabilityInfo(["GD32F103R[FGIK]"]), "4": FootnoteAvailabilityInfo(["GD32F103R[CDEFGIK]"]), "5": FootnoteAvailabilityInfo(["GD32F103R[CDEFGIK]"], "ADC2"), "6": FootnoteAvailabilityInfo(["GD32F103R[8BCDEFGIK]"]) }), + DatasheetPinDefPageParsingInfo([37], "GD32F103Rx", "LQFP64", [ + ParseUsingAreaQuirk((88,123,769,527)), + ], { "3": FootnoteAvailabilityInfo(["GD32F103R[FGIK]"]), "4": FootnoteAvailabilityInfo(["GD32F103R[CDEFGIK]"]), "5": FootnoteAvailabilityInfo(["GD32F103R[CDEFGIK]"], "ADC2"), "6": FootnoteAvailabilityInfo(["GD32F103R[8BCDEFGIK]"]) }), + DatasheetPinDefPageParsingInfo([38], "GD32F103Rx", "LQFP64", [ + ParseUsingAreaQuirk((88,123,769,527)), + OverwritePinDescriptionQuirk("PC12", "Default: PC12\rAlternate: UART4_TX(4), SDIO_CK(4)\nRemap: USART2_CK (6), SPI2_MOSI(4), I2S2_SD(4)"), + ], { "3": FootnoteAvailabilityInfo(["GD32F103R[FGIK]"]), "4": FootnoteAvailabilityInfo(["GD32F103R[CDEFGIK]"]), "5": FootnoteAvailabilityInfo(["GD32F103R[CDEFGIK]"], "ADC2"), "6": FootnoteAvailabilityInfo(["GD32F103R[8BCDEFGIK]"]) }), + DatasheetPinDefPageParsingInfo([39], "GD32F103Rx", "LQFP64", [ + ParseUsingAreaQuirk((135,123,576,527)), + ], { "3": FootnoteAvailabilityInfo(["GD32F103R[FGIK]"]), "4": FootnoteAvailabilityInfo(["GD32F103R[CDEFGIK]"]), "5": FootnoteAvailabilityInfo(["GD32F103R[CDEFGIK]"], "ADC2"), "6": FootnoteAvailabilityInfo(["GD32F103R[8BCDEFGIK]"]) }), + # GD32F103Cx + DatasheetPinDefPageParsingInfo([40], "GD32F103Cx", "LQFP48", [ + ParseUsingAreaQuirk((135,123,769,527)), + OverwritePinDescriptionQuirk("PB1", "Default: PB1\rAlternate: ADC01_IN9, TIMER2_CH3\nRemap: TIMER0_CH2_ON"), + ], { "3": FootnoteAvailabilityInfo(["GD32F103C[468B]"], "ADC2"), "4": FootnoteAvailabilityInfo(["GD32F103C[8B]"]) }), + DatasheetPinDefPageParsingInfo([41], "GD32F103Cx", "LQFP48", [ + ParseUsingAreaQuirk((88,123,769,527)), + OverwritePinDescriptionQuirk("PB3", "Default: JTDO\rRemap: PB3, TRACESWO, TIMER1_CH1, SPI0_SCK"), + ], { "3": FootnoteAvailabilityInfo(["GD32F103C[468B]"], "ADC2"), "4": FootnoteAvailabilityInfo(["GD32F103C[8B]"]) }), + DatasheetPinDefPageParsingInfo([42], "GD32F103Cx", "LQFP48", [ + ParseUsingAreaQuirk((88,123,476,527)), + ], { "3": FootnoteAvailabilityInfo(["GD32F103C[468B]"], "ADC2"), "4": FootnoteAvailabilityInfo(["GD32F103C[8B]"]) }), + # GD32F103Tx + DatasheetPinDefPageParsingInfo([43], "GD32F103Tx", "LQFP36", [ + ParseUsingAreaQuirk((135,123,769,527)), + OverwritePinDescriptionQuirk("PA9", "Default: PA9\rAlternate: USART0_TX, TIMER0_CH1"), + ], { "3": FootnoteAvailabilityInfo(["GD32F103T[468B]"], "ADC2", False), "4": FootnoteAvailabilityInfo(["GD32F103T[8B]"]) }), + DatasheetPinDefPageParsingInfo([44], "GD32F103Tx", "LQFP36", [ + ParseUsingAreaQuirk((88,123,621,527)), + ], { "3": FootnoteAvailabilityInfo(["GD32F103T[468B]"], "ADC2", False), "4": FootnoteAvailabilityInfo(["GD32F103T[8B]"]) }), + ], + series = "GD32F10x", + family_name = "GD32F103xx", + family_type = "A", + internal_adc = { + "ADC_TEMP": ("0", "16"), # (adc, channel) + "ADC_VREF": ("0", "17"), + } + ), } #remapping_infos = [ @@ -483,13 +578,26 @@ "PC11": "SPI2_MOSI", "PC12": "SPI2_MISO/I2S_SD", } + }, + "GD32F103xx": { + "NAME_TIMER3_REMAP": { + "PD12": "TIMER3_CH0" + }, + "NAME_USART2_FULL_REMAP": { + "PD12": "USART2_RTS" + } } } -def get_remapper_infos_for_family(datasheet: DatasheetParsingInfo): - if datasheet.family_name in remapper_infos: - return remapper_infos[datasheet.family_name] - raise RuntimeError("Remapper info not found for family: " + str(datasheet.family_name)) +# This structure will permit remapping of individual pins, but +# what it doesn't describe accurately is the effect remapping +# one pin will have on other pins. For instance, on GD32F103, +# remapping TIMER1_CH2 to PB10 can map TIMER1_CH1 to PA1 or PB3 +# depending on the remap. Thus, this structure is also used to +# provide alternative mappings in the platform, ie PA0_ALT1. +remapper_info = { + **gd32f10x_remap.remapping_info +} def identify_datasheet(datasheet_pdf_path: str) -> DatasheetParsingInfo: global known_datasheets_infos diff --git a/misc/scripts/gd32_genpinmap/parsing_info.py b/misc/scripts/gd32_genpinmap/parsing_info.py index b9fecd1..25c3678 100644 --- a/misc/scripts/gd32_genpinmap/parsing_info.py +++ b/misc/scripts/gd32_genpinmap/parsing_info.py @@ -16,17 +16,32 @@ def __init__(self, page_range: List[int], footnotes_device_availablity: Dict[str super().__init__(page_range, quirks) self.footnotes_device_availability = footnotes_device_availablity +class FootnoteAvailabilityInfo: + def __init__(self, device_filter:List[str], signal_filter:str=None, signal_inclusive:bool=True) -> None: + self.device_filter = device_filter + self.signal_filter = signal_filter + self.signal_inclusive = signal_inclusive + class DatasheetPinDefPageParsingInfo(DatasheetPageParsingInfo): - def __init__(self, page_range: List[int], subseries:str, package:str, quirks:List[DatasheetPageParsingQuirk]=None, footnotes_device_availablity: Dict[str, str]=None) -> None: + def __init__(self, page_range: List[int], subseries:str, package:str, quirks:List[DatasheetPageParsingQuirk]=None, footnotes_device_availablity: Dict[str, FootnoteAvailabilityInfo]=None) -> None: super().__init__(page_range, quirks) self.subseries = subseries self.package = package self.footnotes_device_availability = footnotes_device_availablity class DatasheetParsingInfo: - def __init__(self, alternate_funcs: List[DatasheetAFPageParsingInfo], pin_defs: List[DatasheetPinDefPageParsingInfo], series:str, family_type:str, family_name:str=None) -> None: + def __init__(self, alternate_funcs: List[DatasheetAFPageParsingInfo], pin_defs: List[DatasheetPinDefPageParsingInfo], series:str, family_type:str, family_name:str=None, internal_adc:str=None) -> None: self.alternate_funcs = alternate_funcs self.pin_defs = pin_defs self.series = series self.family_type = family_type - self.family_name = family_name \ No newline at end of file + self.family_name = family_name + self.internal_adc = internal_adc + +class RemappingMacro: + def __init__(self, replacement_macro: str, disable:bool = False, include_packages: List[str] = None, include_subseries: List[str] = None, include_mcus: List[str] = None): + self.replacement_macro = replacement_macro + self.disable = disable + self.include_packages = include_packages + self.include_subseries = include_subseries + self.include_mcus = include_mcus diff --git a/misc/scripts/gd32_genpinmap/pin_definitions.py b/misc/scripts/gd32_genpinmap/pin_definitions.py index 394506d..0b2b76a 100644 --- a/misc/scripts/gd32_genpinmap/pin_definitions.py +++ b/misc/scripts/gd32_genpinmap/pin_definitions.py @@ -1,8 +1,18 @@ +import sys, os, re from typing import Dict, List, Optional +from known_datasheets import remapper_info +from parsing_info import FootnoteAvailabilityInfo, RemappingMacro + +sys.path.insert(1, os.path.join(sys.path[0], '..')) + +from board_generator import GD32MCUInfo + class GD32PinFunction: - def __init__(self, signal_name: str, af_number: int, footnote: str, footnote_device_availability: Dict[str, List[str]], subseries: str = None, package: str = None, needs_remap: bool = False) -> None: + def __init__(self, pin_name: str, signal_name: str, af_number: int, footnote: str, footnote_device_availability: Dict[str, FootnoteAvailabilityInfo], family_type: str, subseries: str = None, package: str = None, needs_remap: bool = False) -> None: + self.pin_name = pin_name self.signal_name = signal_name + self.family_type = family_type self.footnote = footnote self.footnote_device_availability = footnote_device_availability self.footnote_resolved = None @@ -16,8 +26,6 @@ def __init__(self, signal_name: str, af_number: int, footnote: str, footnote_dev self.subseries = subseries self.package = package self.needs_remap = needs_remap - # to be filled in later - self.remapping_activation_macro: str = None try: if "_" in self.signal_name: self.peripheral = self.signal_name.split("_")[0] @@ -35,6 +43,28 @@ def __repr__(self) -> str: def has_af_number(self): return self.af_number is not None + + def remapping_macros(self, mcu: GD32MCUInfo) -> List[str]: + try: + scopes = remapper_info[mcu.spl_series.lower()][self.pin_name][self.signal_name] + validScopes: List[RemappingMacro] = [] + for scope in scopes: + if scope.include_packages and not any(re.search(s, self.package, re.RegexFlag.IGNORECASE) for s in scope.include_packages): + continue + if scope.include_subseries and not any(re.search(s, mcu.sub_series, re.RegexFlag.IGNORECASE) for s in scope.include_subseries): + continue + if scope.include_mcus and not any(re.search(s, mcu.name, re.RegexFlag.IGNORECASE) for s in scope.include_mcus): + continue + validScopes.append(scope) + + if not len(validScopes): raise + + print(f"MATCH for {self.pin_name} ({self.signal_name}) -> {[s.replacement_macro for s in validScopes]}") + return [("DISABLE_" if s.disable else "") + s.replacement_macro for s in validScopes] + except: + print(f"No remapping match found for {self.pin_name} ({self.signal_name})") + + return [] class GD32Pin: def __init__(self, pin_name: str, pin_functions: List[GD32PinFunction]=None) -> None: @@ -44,4 +74,13 @@ def __repr__(self) -> str: return f"GD32Pin(pin={self.pin_name}, funcs={str(self.pin_functions)}" def add_func(self, pin_func:GD32PinFunction): - self.pin_functions.append(pin_func) \ No newline at end of file + self.pin_functions.append(pin_func) + + @staticmethod + def natural_sort_key(pin_name): + key = 0 + # Matches PA1, PA1_ALT1, PORTA_1, PORTA_1_ALT1 + m = re.match("P(ORT)?([A-Z])_?([0-9]+)_?(ALT([0-9]))?", pin_name) + mg = m.groups() + key = "%s%02d%s" % (mg[1], int(mg[2]), mg[4] or "0") + return key \ No newline at end of file diff --git a/misc/scripts/gd32_genpinmap/pin_map.py b/misc/scripts/gd32_genpinmap/pin_map.py index cc68fdf..a1c1d4d 100644 --- a/misc/scripts/gd32_genpinmap/pin_map.py +++ b/misc/scripts/gd32_genpinmap/pin_map.py @@ -1,8 +1,19 @@ +from enum import Enum from typing import Dict, List, Tuple import re from pin_definitions import GD32Pin, GD32PinFunction from parsing_info import DatasheetParsingInfo -from known_datasheets import get_remapper_infos_for_family + +class GD32PinCriteriaType(Enum): + PERIPHERAL_STARTS_WITH = 0 + PIN_SUB_FUNCTION = 1 + PERIPHAL_AND_PIN_SUB_FUNCTION = 2 + SIGNAL_CONTAINS = 3 + +class GD32PinCriteria: + def __init__(self, criteria_type: GD32PinCriteriaType, criteria_values: List[any]) -> None: + self.type = criteria_type + self.values = criteria_values class GD32SubseriesPinMap: def __init__(self, series: str, subseries:str, package:str, datasheet_info:DatasheetParsingInfo, pin_map: Dict[str, GD32Pin]) -> None: @@ -34,10 +45,6 @@ def __init__(self, series: str, datasheet_info:DatasheetParsingInfo, subseries_p subseries_pinmaps = dict() self.subseries_pinmaps = subseries_pinmaps - CRITERIA_PERIPHERAL_STARTS_WITH = 0 - CRITERIA_PIN_SUB_FUNCTION = 1 - CRITERIA_PERIPHAL_AND_PIN_SUB_FUNCTION = 2 - def get_subfamily_for_device_name(self, device_name: str) -> str: # try to identify the family name matching_subfamilies = list(filter( @@ -76,7 +83,7 @@ def pin_is_available_for_device(self, pin_name:str, device_name:str): # devicename = GD32F190T6, constraint = GD32F190Tx => true @staticmethod def devicename_matches_constraint(device_name:str, constraint:str) -> bool: - if "x" not in constraint: + if "x" not in constraint and constraint.isalnum(): # may be regex ret = device_name == constraint else: # replace x with "can be any character" regex @@ -97,9 +104,15 @@ def does_pinfunction_pass_filter(func: GD32PinFunction, device_name:str) -> bool if func.subseries is not None: if not GD32PinMap.devicename_matches_constraint(device_name, func.subseries): return False - return any([GD32PinMap.devicename_matches_constraint(device_name, dev_constraint) for dev_constraint in func.footnote_resolved]) + if func.footnote_resolved.signal_filter: + if func.signal_name.startswith(func.footnote_resolved.signal_filter): + return func.footnote_resolved.signal_inclusive == any([GD32PinMap.devicename_matches_constraint(device_name, dev_constraint) for dev_constraint in func.footnote_resolved.device_filter]) + else: + return True + else: + return any([GD32PinMap.devicename_matches_constraint(device_name, dev_constraint) for dev_constraint in func.footnote_resolved.device_filter]) - def search_pins_for_function(self, criteria_type, criteria_value,filter_device_name:str=None) -> List[Tuple[GD32Pin, GD32PinFunction]]: + def search_pins_for_function(self, pin_criteria:List[GD32PinCriteria], filter_device_name:str=None) -> List[Tuple[GD32Pin, GD32PinFunction]]: results: List[Tuple[GD32Pin, GD32PinFunction]] = list() pin_maps_to_search: List[GD32SubseriesPinMap] if filter_device_name is None: @@ -110,47 +123,28 @@ def search_pins_for_function(self, criteria_type, criteria_value,filter_device_n for pin in pin_map.pin_map.values(): # search through all functions for function in pin.pin_functions: - if criteria_type == GD32PinMap.CRITERIA_PERIPHERAL_STARTS_WITH: - if function.peripheral.startswith(criteria_value): - results.append((pin, function)) - elif criteria_type == GD32PinMap.CRITERIA_PIN_SUB_FUNCTION: - if function.subfunction is not None and criteria_value in function.subfunction: - results.append((pin, function)) - elif criteria_type == GD32PinMap.CRITERIA_PERIPHAL_AND_PIN_SUB_FUNCTION: - if function.peripheral.startswith(criteria_value[0]) and (function.subfunction is not None and criteria_value[1] in function.subfunction): - results.append((pin, function)) + # all pin_criteria are AND, but values are OR: + # PERIPHERAL_STARTS_WITH("A" OR "B") AND SIGNAL_CONTAINS("C") + all_criteria_passed = True + for criteria in pin_criteria: + criteria_passed = False + if criteria.type == GD32PinCriteriaType.PERIPHERAL_STARTS_WITH: + if any(function.peripheral.startswith(value) for value in criteria.values): + criteria_passed = True + elif criteria.type == GD32PinCriteriaType.PIN_SUB_FUNCTION: + if any((function.subfunction is not None and value in function.subfunction) for value in criteria.values): + criteria_passed = True + elif criteria.type == GD32PinCriteriaType.PERIPHAL_AND_PIN_SUB_FUNCTION: + if any((function.peripheral.startswith(value[0]) and (function.subfunction is not None and value[1] in function.subfunction)) for value in criteria.values): + criteria_passed = True + elif criteria.type == GD32PinCriteriaType.SIGNAL_CONTAINS: + if any((value in function.signal_name) for value in criteria.values): + criteria_passed = True + all_criteria_passed &= criteria_passed + if all_criteria_passed: + results.append((pin, function)) results = list(filter(lambda p_func_tuple: GD32PinMap.does_pinfunction_pass_filter(p_func_tuple[1], filter_device_name), results)) results = list(filter(lambda p_func_tuple: self.pin_is_available_for_device(p_func_tuple[0].pin_name, filter_device_name), results)) + results.sort(key=lambda x: GD32Pin.natural_sort_key(x[0].pin_name) + x[1].signal_name) return results - - def solve_remapper_pin(self, pin_name:str, pin_func: GD32PinFunction) -> str: - remapping_info = get_remapper_infos_for_family(self.datasheet_info) - # check if any macro knows this thing - sig_name = pin_func.signal_name - matches: List[str] = list() - for macro_name, pin_map in remapping_info.items(): - if pin_name in pin_map: - if sig_name in pin_map[pin_name]: - print(f"MATCH for {pin_name} ({sig_name}) -> {macro_name}") - matches.append(macro_name) - # if we have multiple matches, prefer the one the "FULL" remap - if len(matches) > 1: - full_macros = list(filter(lambda m: "FULL" in m, matches)) - if len(full_macros) == 1: - return full_macros[0] - else: - print(f"Multiple possibilities found for {pin_name} ({sig_name}) and no FULL in name, returning first one.") - return matches[0] - elif len(matches) == 1: - return matches[0] - print(f"No remapping match found for {pin_name} ({sig_name})") - return None - - def solve_remapper_pins(self): - for subfamily in self.subseries_pinmaps: - pinmap = self.subseries_pinmaps[subfamily].pin_map - for pin_name, pin_info in pinmap.items(): - for pin_func in pin_info.pin_functions: - if pin_func.needs_remap: - print(f"[{subfamily}] Pin {pin_name} ({pin_func.signal_name}) needs remapping info!") - pin_func.remapping_activation_macro = self.solve_remapper_pin(pin_name, pin_func) \ No newline at end of file + \ No newline at end of file diff --git a/misc/scripts/gd32_genpinmap/pinmap_converter.py b/misc/scripts/gd32_genpinmap/pinmap_converter.py index e9b7a22..ddbb754 100644 --- a/misc/scripts/gd32_genpinmap/pinmap_converter.py +++ b/misc/scripts/gd32_genpinmap/pinmap_converter.py @@ -1,12 +1,11 @@ -from typing import Dict, Tuple, List +from collections import defaultdict +from typing import Callable, Dict, Tuple, List, TypeVar, Iterable from func_utils import get_trailing_number, print_big_str, natural_keys, remove_last_comma, write_to_file, natural_key_for_pin_func -from known_datasheets import identify_datasheet from pin_definitions import GD32Pin, GD32PinFunction -from pin_map import GD32PinMap, GD32SubseriesPinMap -from datasheet_parser import GD32DatasheetParser +from pin_map import GD32PinCriteria, GD32PinCriteriaType, GD32PinMap from static_data import * from os import mkdir, path -import string +import string, re import sys from pathlib import Path # if you haven't already done so file = Path(__file__).resolve() @@ -18,9 +17,7 @@ class GD32PinMapGenerator: @staticmethod def get_adc_pins(pinmap: GD32PinMap, device_name:str) -> List[Tuple[GD32Pin, GD32PinFunction]]: - l = pinmap.search_pins_for_function(GD32PinMap.CRITERIA_PERIPHERAL_STARTS_WITH, "ADC", filter_device_name=device_name) - l.sort(key=natural_key_for_pin_func) # to get that nice ADC_IN0.. ADC_IN11 ordering correct - return l + return pinmap.search_pins_for_function([GD32PinCriteria(GD32PinCriteriaType.PERIPHERAL_STARTS_WITH, ["ADC"])], filter_device_name=device_name) @staticmethod def get_adc_pinnames(pinmap: GD32PinMap, device_name:str) -> List[str]: @@ -37,76 +34,93 @@ def get_non_adc_pinnames(pinmap: GD32PinMap, device_name:str) -> List[str]: non_adc_pins = list(filter(lambda p: p not in adc_pins, subfam.pin_map.keys())) return non_adc_pins + @staticmethod + def get_alt_pinnames(pinmap: GD32PinMap, mcu:GD32MCUInfo) -> List[str]: + subfam = pinmap.get_subfamily_for_device_name(mcu.name_no_package) + if subfam is None: + return list() + subfam = pinmap.subseries_pinmaps[subfam] + alt_pinnames = [] + for pin_info in subfam.pin_map.values(): + if len(pin_info.pin_functions): + nalts = max([len(func.remapping_macros(mcu) or []) for func in pin_info.pin_functions]) + if nalts: + alt_pinnames += [f"{pin_info.pin_name}_ALT{alt} ({pin_info.pin_name} | ALT{alt})" for alt in range(1, nalts)] + return alt_pinnames + + @staticmethod + def get_all_alt_pins(peripheral_c: str) -> List[str]: + alt_match = re.findall("PORT[A-Z]_[0-9]+_ALT[0-9]", peripheral_c) or [] + return sorted(set(alt_match), key=GD32Pin.natural_sort_key) + @staticmethod def get_dac_pins(pinmap: GD32PinMap, device_name:str) -> List[Tuple[GD32Pin, GD32PinFunction]]: - return pinmap.search_pins_for_function(GD32PinMap.CRITERIA_PERIPHERAL_STARTS_WITH, "DAC", filter_device_name=device_name) + return pinmap.search_pins_for_function([GD32PinCriteria(GD32PinCriteriaType.PERIPHERAL_STARTS_WITH, ["DAC"])], filter_device_name=device_name) @staticmethod def get_i2c_sda_pins(pinmap: GD32PinMap, device_name:str) -> List[Tuple[GD32Pin, GD32PinFunction]]: - return pinmap.search_pins_for_function(GD32PinMap.CRITERIA_PERIPHAL_AND_PIN_SUB_FUNCTION, ("I2C", "SDA"), filter_device_name=device_name) + return pinmap.search_pins_for_function([GD32PinCriteria(GD32PinCriteriaType.PERIPHAL_AND_PIN_SUB_FUNCTION, [("I2C", "SDA")])], filter_device_name=device_name) @staticmethod def get_i2c_scl_pins(pinmap: GD32PinMap, device_name:str) -> List[Tuple[GD32Pin, GD32PinFunction]]: - return pinmap.search_pins_for_function(GD32PinMap.CRITERIA_PERIPHAL_AND_PIN_SUB_FUNCTION, ("I2C", "SCL"), filter_device_name=device_name) + return pinmap.search_pins_for_function([GD32PinCriteria(GD32PinCriteriaType.PERIPHAL_AND_PIN_SUB_FUNCTION, [("I2C", "SCL")])], filter_device_name=device_name) @staticmethod def get_pwm_pins(pinmap: GD32PinMap, device_name:str) -> List[Tuple[GD32Pin, GD32PinFunction]]: - all_timers = pinmap.search_pins_for_function(GD32PinMap.CRITERIA_PERIPHERAL_STARTS_WITH, "TIMER", filter_device_name=device_name) - all_timers = list(filter(lambda p_func: "_CH" in p_func[1].signal_name, all_timers)) - return all_timers + return pinmap.search_pins_for_function([ + GD32PinCriteria(GD32PinCriteriaType.PERIPHERAL_STARTS_WITH, ["TIMER"]), + GD32PinCriteria(GD32PinCriteriaType.SIGNAL_CONTAINS, ["_CH"]) + ], + filter_device_name=device_name) @staticmethod def get_uart_tx_pins(pinmap: GD32PinMap, device_name:str) -> List[Tuple[GD32Pin, GD32PinFunction]]: - res = pinmap.search_pins_for_function(GD32PinMap.CRITERIA_PERIPHAL_AND_PIN_SUB_FUNCTION, ("USART", "TX"), filter_device_name=device_name) - return res + pinmap.search_pins_for_function(GD32PinMap.CRITERIA_PERIPHAL_AND_PIN_SUB_FUNCTION, ("UART", "TX"), filter_device_name=device_name) + return pinmap.search_pins_for_function([GD32PinCriteria(GD32PinCriteriaType.PERIPHAL_AND_PIN_SUB_FUNCTION, [("USART", "TX"), ("UART", "TX")])], filter_device_name=device_name) @staticmethod def get_uart_rx_pins(pinmap: GD32PinMap, device_name:str) -> List[Tuple[GD32Pin, GD32PinFunction]]: - res = pinmap.search_pins_for_function(GD32PinMap.CRITERIA_PERIPHAL_AND_PIN_SUB_FUNCTION, ("USART", "RX"), filter_device_name=device_name) - return res + pinmap.search_pins_for_function(GD32PinMap.CRITERIA_PERIPHAL_AND_PIN_SUB_FUNCTION, ("UART", "RX"), filter_device_name=device_name) + return pinmap.search_pins_for_function([GD32PinCriteria(GD32PinCriteriaType.PERIPHAL_AND_PIN_SUB_FUNCTION, [("USART", "RX"), ("UART", "RX")])], filter_device_name=device_name) @staticmethod def get_uart_rts_pins(pinmap: GD32PinMap, device_name:str) -> List[Tuple[GD32Pin, GD32PinFunction]]: - res = pinmap.search_pins_for_function(GD32PinMap.CRITERIA_PERIPHAL_AND_PIN_SUB_FUNCTION, ("USART", "RTS"), filter_device_name=device_name) - return res + pinmap.search_pins_for_function(GD32PinMap.CRITERIA_PERIPHAL_AND_PIN_SUB_FUNCTION, ("UART", "RTS"), filter_device_name=device_name) + return pinmap.search_pins_for_function([GD32PinCriteria(GD32PinCriteriaType.PERIPHAL_AND_PIN_SUB_FUNCTION, [("USART", "RTS"), ("UART", "RTS")])], filter_device_name=device_name) @staticmethod def get_uart_cts_pins(pinmap: GD32PinMap, device_name:str) -> List[Tuple[GD32Pin, GD32PinFunction]]: - res = pinmap.search_pins_for_function(GD32PinMap.CRITERIA_PERIPHAL_AND_PIN_SUB_FUNCTION, ("USART", "CTS"), filter_device_name=device_name) - return res + pinmap.search_pins_for_function(GD32PinMap.CRITERIA_PERIPHAL_AND_PIN_SUB_FUNCTION, ("UART", "CTS"), filter_device_name=device_name) + return pinmap.search_pins_for_function([GD32PinCriteria(GD32PinCriteriaType.PERIPHAL_AND_PIN_SUB_FUNCTION, [("USART", "CTS"), ("UART", "CTS")])], filter_device_name=device_name) @staticmethod def get_spi_mosi_pins(pinmap: GD32PinMap, device_name:str) -> List[Tuple[GD32Pin, GD32PinFunction]]: - return pinmap.search_pins_for_function(GD32PinMap.CRITERIA_PERIPHAL_AND_PIN_SUB_FUNCTION, ("SPI", "MOSI"), filter_device_name=device_name) + return pinmap.search_pins_for_function([GD32PinCriteria(GD32PinCriteriaType.PERIPHAL_AND_PIN_SUB_FUNCTION, [("SPI", "MOSI")])], filter_device_name=device_name) @staticmethod def get_spi_miso_pins(pinmap: GD32PinMap, device_name:str) -> List[Tuple[GD32Pin, GD32PinFunction]]: - return pinmap.search_pins_for_function(GD32PinMap.CRITERIA_PERIPHAL_AND_PIN_SUB_FUNCTION, ("SPI", "MISO"), filter_device_name=device_name) + return pinmap.search_pins_for_function([GD32PinCriteria(GD32PinCriteriaType.PERIPHAL_AND_PIN_SUB_FUNCTION, [("SPI", "MISO")])], filter_device_name=device_name) @staticmethod def get_spi_sclk_pins(pinmap: GD32PinMap, device_name:str) -> List[Tuple[GD32Pin, GD32PinFunction]]: - return pinmap.search_pins_for_function(GD32PinMap.CRITERIA_PERIPHAL_AND_PIN_SUB_FUNCTION, ("SPI", "SCK"), filter_device_name=device_name) + return pinmap.search_pins_for_function([GD32PinCriteria(GD32PinCriteriaType.PERIPHAL_AND_PIN_SUB_FUNCTION, [("SPI", "SCK")])], filter_device_name=device_name) @staticmethod def get_spi_nss_pins(pinmap: GD32PinMap, device_name:str) -> List[Tuple[GD32Pin, GD32PinFunction]]: - return pinmap.search_pins_for_function(GD32PinMap.CRITERIA_PERIPHAL_AND_PIN_SUB_FUNCTION, ("SPI", "NSS"), filter_device_name=device_name) + return pinmap.search_pins_for_function([GD32PinCriteria(GD32PinCriteriaType.PERIPHAL_AND_PIN_SUB_FUNCTION, [("SPI", "NSS")])], filter_device_name=device_name) @staticmethod def get_can_rd_pins(pinmap: GD32PinMap, device_name:str) -> List[Tuple[GD32Pin, GD32PinFunction]]: - return pinmap.search_pins_for_function(GD32PinMap.CRITERIA_PERIPHAL_AND_PIN_SUB_FUNCTION, ("CAN", "RX"), filter_device_name=device_name) + return pinmap.search_pins_for_function([GD32PinCriteria(GD32PinCriteriaType.PERIPHAL_AND_PIN_SUB_FUNCTION, [("CAN", "RX")])], filter_device_name=device_name) @staticmethod def get_can_td_pins(pinmap: GD32PinMap, device_name:str) -> List[Tuple[GD32Pin, GD32PinFunction]]: - return pinmap.search_pins_for_function(GD32PinMap.CRITERIA_PERIPHAL_AND_PIN_SUB_FUNCTION, ("CAN", "TX"), filter_device_name=device_name) + return pinmap.search_pins_for_function([GD32PinCriteria(GD32PinCriteriaType.PERIPHAL_AND_PIN_SUB_FUNCTION, [("CAN", "TX")])], filter_device_name=device_name) # ToDo: check if it makes sense to declare these. (CAN builtin PHY pins) @staticmethod def get_can_h_pins(pinmap: GD32PinMap, device_name:str) -> List[Tuple[GD32Pin, GD32PinFunction]]: - return pinmap.search_pins_for_function(GD32PinMap.CRITERIA_PERIPHAL_AND_PIN_SUB_FUNCTION, ("", "CANH"), filter_device_name=device_name) + return pinmap.search_pins_for_function([GD32PinCriteria(GD32PinCriteriaType.PERIPHAL_AND_PIN_SUB_FUNCTION, [("", "CANH")])], filter_device_name=device_name) @staticmethod def get_can_l_pins(pinmap: GD32PinMap, device_name:str) -> List[Tuple[GD32Pin, GD32PinFunction]]: - return pinmap.search_pins_for_function(GD32PinMap.CRITERIA_PERIPHAL_AND_PIN_SUB_FUNCTION, ("", "CANL"), filter_device_name=device_name) + return pinmap.search_pins_for_function([GD32PinCriteria(GD32PinCriteriaType.PERIPHAL_AND_PIN_SUB_FUNCTION, [("", "CANL")])], filter_device_name=device_name) @staticmethod def begin_pinmap(name:str): @@ -121,13 +135,33 @@ def format_pin_to_port_pin(pin_name:str) -> str: port_ident = pin_name[1] pin_num = pin_name[2:] return "PORT%s_%s" % (port_ident, pin_num) + + @staticmethod + def get_chan_num(func: GD32PinFunction): + chan_num = 0 + sig_split = func.signal_name.split("TIMER") + sig_split = [x.replace(",","") for x in sig_split] + + # we probably want to remember that "_ON" thing and + # give it in the pinmap? don't fully understand PWM yet, but + # there is the GD_PIN_CHON_GET() macro. + sig_split = [x.replace("_ON","") for x in sig_split] + if len(sig_split) >= 2: + chan_num = get_trailing_number(sig_split[1]) + + #print(pin.pin_name) + #print(func.signal_name) + #print(sig_split) + #print(chan_num) + return chan_num + @staticmethod def add_pin_text(pin_and_port:str, periph:str, function_bits:str, signal_name:str, commented_out:bool = False, width:int = 50): temp = "%s {%s,%s %s,%s%s}," % ( "" if commented_out is False else "//", pin_and_port, - " " * (len("PORTA_15") - len(pin_and_port)), + " " * (len("PORTA_15_ALT1") - len(pin_and_port)), periph, " " if "TIMER" not in periph else " " * (len("TIMER_15") - len(periph)), function_bits @@ -137,21 +171,44 @@ def add_pin_text(pin_and_port:str, periph:str, function_bits:str, signal_name:st return temp @staticmethod - def add_pin(pin: GD32Pin, func: GD32PinFunction, function_bits:str, commented_out:bool = False, width:int = 50): + def add_pin(pin: GD32Pin, func: GD32PinFunction, function_bits:str, commented_out:bool = False, width:int = 50, alt:int = 0): return GD32PinMapGenerator.add_pin_text( - GD32PinMapGenerator.format_pin_to_port_pin(pin.pin_name), + GD32PinMapGenerator.format_pin_to_port_pin(pin.pin_name) + ("_ALT" + str(alt) if alt > 0 else ""), func.peripheral, function_bits, func.signal_name, commented_out, width ) + + @staticmethod + def add_alt_pins(pin:GD32Pin, func:GD32PinFunction, function_bits, remapping_macros: any, commented_out:bool, alt: int = 0): + retStr = "" + for remapping_macro in remapping_macros: + retStr += GD32PinMapGenerator.add_pin( + pin, func, function_bits % remapping_macro, commented_out, alt=alt) + alt += 1 + return retStr @staticmethod - def add_adc_pin(pin: GD32Pin, func: GD32PinFunction) -> str: + def add_adc_pin(pin: GD32Pin, func: GD32PinFunction, mcu:GD32MCUInfo, context: any) -> str: chan_num = get_trailing_number(func.signal_name) - return GD32PinMapGenerator.add_pin( - pin, func, "GD_PIN_FUNC_ANALOG_CH(%d)" % chan_num, False) + alt = context["alt"] + if func.family_type == "A": + remapping_macros = func.remapping_macros(mcu) + context["alt"] += len(remapping_macros) or 1 + if len(remapping_macros): + return GD32PinMapGenerator.add_alt_pins( + pin, func, "GD_PIN_FUNC_ANALOG_CH(%d)", [chan_num] * len(remapping_macros), False, alt) + else: + return GD32PinMapGenerator.add_pin( + pin, func, "GD_PIN_FUNC_ANALOG_CH(%d)" % chan_num, False, alt=alt) + elif func.family_type == "B": + context["alt"] += 1 + return GD32PinMapGenerator.add_pin( + pin, func, "GD_PIN_FUNC_ANALOG_CH(%d)" % chan_num, False, alt=alt) + else: + raise Exception("Unknown family_type: %s" % func.family_type) @staticmethod def add_dac_pin(pin: GD32Pin, func: GD32PinFunction) -> str: @@ -162,62 +219,92 @@ def add_dac_pin(pin: GD32Pin, func: GD32PinFunction) -> str: pin, func, "GD_PIN_FUNC_ANALOG_CH(%d)" % chan_num, False) @staticmethod - def add_i2c_pin(pin: GD32Pin, func: GD32PinFunction) -> str: - af_num = func.af_number - return GD32PinMapGenerator.add_pin( - pin, func, "GD_PIN_FUNCTION4(PIN_MODE_AF, PIN_OTYPE_OD, PIN_PUPD_PULLUP, IND_GPIO_AF_%d)" % af_num, False) - - @staticmethod - def add_uart_pin(pin: GD32Pin, func: GD32PinFunction) -> str: - af_num = func.af_number - if func.has_af_number(): - return GD32PinMapGenerator.add_pin( - pin, func, "GD_PIN_FUNCTION4(PIN_MODE_AF, GPIO_OTYPE_PP, PIN_PUPD_PULLUP, IND_GPIO_AF_%d)" % af_num, False) - else: - # output driving - if any([x in func.signal_name for x in ("TX", "CTS", "RTS")]): + def add_i2c_pin(pin: GD32Pin, func: GD32PinFunction, mcu: GD32MCUInfo, context) -> str: + if func.family_type == "A": + alt = context["alt"] + remapping_macros = func.remapping_macros(mcu) + context["alt"] += len(remapping_macros) or 1 + if remapping_macros and len(remapping_macros): + return GD32PinMapGenerator.add_alt_pins(pin, func, "GD_PIN_FUNCTION5(PIN_MODE_AF, PIN_OTYPE_PP, PIN_PUPD_PULLUP, %s)", remapping_macros, False, alt) + else: + return GD32PinMapGenerator.add_pin(pin, func, "7", False) + elif func.family_type is "B": + if func.has_af_number(): return GD32PinMapGenerator.add_pin( - pin, func, "7", False) - # input + pin, func, "GD_PIN_FUNCTION4(PIN_MODE_AF, PIN_OTYPE_OD, PIN_PUPD_PULLUP, IND_GPIO_AF_%d)" % func.af_number, False) else: + raise Exception("Alternate function number must be provided to enable i2c AF on B family devices") + else: + raise Exception("Unknown family_type: %s" % func.family_type) + + @staticmethod + def add_uart_pin(pin: GD32Pin, func: GD32PinFunction, mcu: GD32MCUInfo, context) -> str: + alt = 0 + if func.family_type == "A": + alt = context["alt"] + remapping_macros = func.remapping_macros(mcu) + context["alt"] += len(remapping_macros) or 1 + if remapping_macros and len(remapping_macros): + return GD32PinMapGenerator.add_alt_pins(pin, func, "GD_PIN_FUNCTION5(PIN_MODE_AF, PIN_OTYPE_PP, PIN_PUPD_PULLUP, %s)", remapping_macros, False, alt) + elif func.family_type == "B": + if func.has_af_number(): return GD32PinMapGenerator.add_pin( - pin, func, "1", False) - - @staticmethod - def add_standard_af_pin(pin: GD32Pin, func: GD32PinFunction) -> str: - af_num = func.af_number - if func.has_af_number(): - return GD32PinMapGenerator.add_pin( - pin, func, "GD_PIN_FUNCTION4(PIN_MODE_AF, GPIO_OTYPE_PP, PIN_PUPD_NONE, IND_GPIO_AF_%d)" % af_num, False) + pin, func, "GD_PIN_FUNCTION4(PIN_MODE_AF, PIN_OTYPE_PP, PIN_PUPD_PULLUP, IND_GPIO_AF_%d)" % func.af_number, False) else: - # not correct for all cases like CAN_RD, FIXME - return GD32PinMapGenerator.add_pin( - pin, func, "7", False) - - @staticmethod - def add_pwm_pin(pin: GD32Pin, func: GD32PinFunction) -> str: - chan_num = 0 - sig_split = func.signal_name.split("TIMER") - sig_split = [x.replace(",","") for x in sig_split] - # we probably want to remember that "_ON" thing and - # give it in the pinmap? don't fully understand PWM yet, but - # there is the GD_PIN_CHON_GET() macro. - sig_split = [x.replace("_ON","") for x in sig_split] - if len(sig_split) >= 2: - chan_num = get_trailing_number(sig_split[1]) - af_num = func.af_number - #print(pin.pin_name) - #print(func.signal_name) - #print(sig_split) - #print(chan_num) - #print(af_num) - if func.has_af_number(): + raise Exception("Unknown family_type: %s" % func.family_type) + + # output driving + if any([x in func.signal_name for x in ("TX", "CTS", "RTS")]): return GD32PinMapGenerator.add_pin( - pin, func, "GD_PIN_FUNC_PWM(%d, IND_GPIO_AF_%d)" % (chan_num, af_num), False) + pin, func, "7", False, alt=alt) + # input else: return GD32PinMapGenerator.add_pin( - pin, func, "GD_PIN_FUNC_PWM_2(%d)" % (chan_num), False) + pin, func, "1", False, alt=alt) + + @staticmethod + def add_standard_af_pin(pin: GD32Pin, func: GD32PinFunction, mcu: GD32MCUInfo, context) -> str: + alt = 0 + if func.family_type == "A": + alt = context["alt"] + remapping_macros = func.remapping_macros(mcu) + context["alt"] += len(remapping_macros) or 1 + if remapping_macros and len(remapping_macros): + return GD32PinMapGenerator.add_alt_pins(pin, func, "GD_PIN_FUNCTION5(PIN_MODE_AF, PIN_OTYPE_PP, PIN_PUPD_PULLUP, %s)", remapping_macros, False, alt) + elif func.family_type == "B": + af_num = func.af_number + if func.has_af_number(): + return GD32PinMapGenerator.add_pin( + pin, func, "GD_PIN_FUNCTION4(PIN_MODE_AF, PIN_OTYPE_PP, PIN_PUPD_NONE, IND_GPIO_AF_%d)" % af_num, False) + else: + raise Exception("Unknown family_type: %s" % func.family_type) + # not correct for all cases like CAN_RD, FIXME + return GD32PinMapGenerator.add_pin( + pin, func, "7", False, alt=alt) + + @staticmethod + def add_pwm_pin(pin: GD32Pin, func: GD32PinFunction, mcu:GD32MCUInfo, context) -> str: + if func.family_type == "A": + alt = context["alt"] + chan_num = GD32PinMapGenerator.get_chan_num(func) + remapping_macros = [(chan_num, m) for m in func.remapping_macros(mcu)] + context["alt"] += len(remapping_macros) or 1 + return GD32PinMapGenerator.add_alt_pins( + pin, func, "GD_PIN_FUNC_PWM(%d, %s)", remapping_macros if len(remapping_macros) else [(chan_num, "0")], False, alt) + elif func.family_type == "B": + ret = "" + chan_num = GD32PinMapGenerator.get_chan_num(func) + af_num = func.af_number + if func.has_af_number(): + #print(af_num) + ret += GD32PinMapGenerator.add_pin( + pin, func, "GD_PIN_FUNC_PWM(%d, IND_GPIO_AF_%d)" % (chan_num, af_num), False) + else: + raise Exception("Alternate function number must be provided to enable PWM AF on B family devices") + else: + raise Exception("Unknown family_type: %s" % func.family_type) + @staticmethod def add_gpio_ports(pinmap:GD32PinMap, device_name:str) -> str: temp = "const uint32_t gpio_port[] = {\n" @@ -245,12 +332,37 @@ def add_all_gpio_pins() -> str: temp += ",\n".join(all_pins) temp += "\n};\n\n" return temp + + T = TypeVar("T") + R = TypeVar("R") + + # itertools.groupby would need a sorted list + @staticmethod + def groupby(l: Iterable[T], key: Callable[[T],R]) -> Dict[R, T]: + d = defaultdict(list) + for item in l: + d[key(item)].append(item) + return d.items() + + @staticmethod + def exec_by_pin_group(pins: List[Tuple[GD32Pin, GD32PinFunction]], function:Callable[[GD32Pin, GD32PinFunction, any], str], context: Callable[[], any] = lambda: {"alt": 0}) -> str: + output = "" + # group all functions together by pin name + for p, fs in ((i, [j[1] for j in j]) for i, j in GD32PinMapGenerator.groupby(pins, lambda x: x[0])): + func_context = context() + for f in fs: + output += function(p, f, func_context) + return output # generation methods @staticmethod - def generate_arduino_peripheralpins_c(pinmap:GD32PinMap, device_name:str) -> str: + def generate_arduino_peripheralpins_c(pinmap:GD32PinMap, mcu:GD32MCUInfo) -> str: + device_name = mcu.name_no_package output = gigadevice_header - output += spl_family_b_peripheral_pins_c_header + if pinmap.datasheet_info.family_type == "B": + output += spl_family_b_peripheral_pins_c_header + elif pinmap.datasheet_info.family_type == "A": + output += spl_family_a_peripheral_pins_c_header.replace("GD32_FAMILY_REMAP_HEADER", f"{mcu.spl_series.lower()}_remap.h") # small correction for header: remove AF above 6 if device_name.lower().startswith("gd32e23"): output = output.replace(" GPIO_AF_7, /* 7 */\n", "") @@ -261,14 +373,20 @@ def generate_arduino_peripheralpins_c(pinmap:GD32PinMap, device_name:str) -> str output = output.replace(" GPIO_AF_11 /* 9 */\n", "") # ADC output += GD32PinMapGenerator.begin_pinmap("ADC") - for p, f in GD32PinMapGenerator.get_adc_pins(pinmap, device_name): - output += GD32PinMapGenerator.add_adc_pin(p, f) + output += GD32PinMapGenerator.exec_by_pin_group( + GD32PinMapGenerator.get_adc_pins(pinmap, device_name), + lambda p, f, context: GD32PinMapGenerator.add_adc_pin(p, f, mcu, context)) # ToDo: The "ADC" might actaully be "ADC0" ("ADC1"?) for some chips. # Channel 16 and 17 should be correct. - output += GD32PinMapGenerator.add_pin_text( - "ADC_TEMP", "ADC", "GD_PIN_FUNC_ANALOG_CH(16)", "ADC_IN16") - output += GD32PinMapGenerator.add_pin_text( - "ADC_VREF", "ADC", "GD_PIN_FUNC_ANALOG_CH(17)", "ADC_IN17") + if pinmap.datasheet_info.internal_adc != None: + for (adc_name, (adc, channel)) in pinmap.datasheet_info.internal_adc.items(): + output += GD32PinMapGenerator.add_pin_text( + adc_name, "ADC%s" %(adc or ""), "GD_PIN_FUNC_ANALOG_CH(%s)" % channel, "ADC%s_IN%s" %(adc or "", channel)) + else: + output += GD32PinMapGenerator.add_pin_text( + "ADC_TEMP", "ADC", "GD_PIN_FUNC_ANALOG_CH(16)", "ADC_IN16") + output += GD32PinMapGenerator.add_pin_text( + "ADC_VREF", "ADC", "GD_PIN_FUNC_ANALOG_CH(17)", "ADC_IN17") output += GD32PinMapGenerator.end_pinmap() # DAC output += GD32PinMapGenerator.begin_pinmap("DAC") @@ -280,68 +398,81 @@ def generate_arduino_peripheralpins_c(pinmap:GD32PinMap, device_name:str) -> str output += GD32PinMapGenerator.end_pinmap() # I2C SDA output += GD32PinMapGenerator.begin_pinmap("I2C_SDA") - for p, f in GD32PinMapGenerator.get_i2c_sda_pins(pinmap, device_name): - output += GD32PinMapGenerator.add_i2c_pin(p, f) + output += GD32PinMapGenerator.exec_by_pin_group( + GD32PinMapGenerator.get_i2c_sda_pins(pinmap, device_name), + lambda p, f, context: GD32PinMapGenerator.add_i2c_pin(p, f, mcu, context)) output += GD32PinMapGenerator.end_pinmap() # I2C SCL output += GD32PinMapGenerator.begin_pinmap("I2C_SCL") - for p, f in GD32PinMapGenerator.get_i2c_scl_pins(pinmap, device_name): - output += GD32PinMapGenerator.add_i2c_pin(p, f) + output += GD32PinMapGenerator.exec_by_pin_group( + GD32PinMapGenerator.get_i2c_scl_pins(pinmap, device_name), + lambda p, f, context: GD32PinMapGenerator.add_i2c_pin(p, f, mcu, context)) output += GD32PinMapGenerator.end_pinmap() # PWM output += GD32PinMapGenerator.begin_pinmap("PWM") - for p, f in GD32PinMapGenerator.get_pwm_pins(pinmap, device_name): - output += GD32PinMapGenerator.add_pwm_pin(p, f) + output += GD32PinMapGenerator.exec_by_pin_group( + GD32PinMapGenerator.get_pwm_pins(pinmap, device_name), + lambda p, f, context: GD32PinMapGenerator.add_pwm_pin(p, f, mcu, context)) output += GD32PinMapGenerator.end_pinmap() # UART TX output += GD32PinMapGenerator.begin_pinmap("UART_TX") - for p, f in GD32PinMapGenerator.get_uart_tx_pins(pinmap, device_name): - output += GD32PinMapGenerator.add_uart_pin(p, f) + output += GD32PinMapGenerator.exec_by_pin_group( + GD32PinMapGenerator.get_uart_tx_pins(pinmap, device_name), + lambda p, f, context: GD32PinMapGenerator.add_uart_pin(p, f, mcu, context)) output += GD32PinMapGenerator.end_pinmap() # UART RX output += GD32PinMapGenerator.begin_pinmap("UART_RX") - for p, f in GD32PinMapGenerator.get_uart_rx_pins(pinmap, device_name): - output += GD32PinMapGenerator.add_uart_pin(p, f) + output += GD32PinMapGenerator.exec_by_pin_group( + GD32PinMapGenerator.get_uart_rx_pins(pinmap, device_name), + lambda p, f, context: GD32PinMapGenerator.add_uart_pin(p, f, mcu, context)) output += GD32PinMapGenerator.end_pinmap() # UART RTS output += GD32PinMapGenerator.begin_pinmap("UART_RTS") - for p, f in GD32PinMapGenerator.get_uart_rts_pins(pinmap, device_name): - output += GD32PinMapGenerator.add_standard_af_pin(p, f) + output += GD32PinMapGenerator.exec_by_pin_group( + GD32PinMapGenerator.get_uart_rts_pins(pinmap, device_name), + lambda p, f, context: GD32PinMapGenerator.add_standard_af_pin(p, f, mcu, context)) output += GD32PinMapGenerator.end_pinmap() # UART CTS output += GD32PinMapGenerator.begin_pinmap("UART_CTS") - for p, f in GD32PinMapGenerator.get_uart_cts_pins(pinmap, device_name): - output += GD32PinMapGenerator.add_standard_af_pin(p, f) + output += GD32PinMapGenerator.exec_by_pin_group( + GD32PinMapGenerator.get_uart_cts_pins(pinmap, device_name), + lambda p, f, context: GD32PinMapGenerator.add_standard_af_pin(p, f, mcu, context)) output += GD32PinMapGenerator.end_pinmap() # SPI MOSI output += GD32PinMapGenerator.begin_pinmap("SPI_MOSI") - for p, f in GD32PinMapGenerator.get_spi_mosi_pins(pinmap, device_name): - output += GD32PinMapGenerator.add_standard_af_pin(p, f) + output += GD32PinMapGenerator.exec_by_pin_group( + GD32PinMapGenerator.get_spi_mosi_pins(pinmap, device_name), + lambda p, f, context: GD32PinMapGenerator.add_standard_af_pin(p, f, mcu, context)) output += GD32PinMapGenerator.end_pinmap() # SPI MISO output += GD32PinMapGenerator.begin_pinmap("SPI_MISO") - for p, f in GD32PinMapGenerator.get_spi_miso_pins(pinmap, device_name): - output += GD32PinMapGenerator.add_standard_af_pin(p, f) + output += GD32PinMapGenerator.exec_by_pin_group( + GD32PinMapGenerator.get_spi_miso_pins(pinmap, device_name), + lambda p, f, context: GD32PinMapGenerator.add_standard_af_pin(p, f, mcu, context)) output += GD32PinMapGenerator.end_pinmap() # SPI SCLK output += GD32PinMapGenerator.begin_pinmap("SPI_SCLK") - for p, f in GD32PinMapGenerator.get_spi_sclk_pins(pinmap, device_name): - output += GD32PinMapGenerator.add_standard_af_pin(p, f) + output += GD32PinMapGenerator.exec_by_pin_group( + GD32PinMapGenerator.get_spi_sclk_pins(pinmap, device_name), + lambda p, f, context: GD32PinMapGenerator.add_standard_af_pin(p, f, mcu, context)) output += GD32PinMapGenerator.end_pinmap() # SPI SSEL output += GD32PinMapGenerator.begin_pinmap("SPI_SSEL") - for p, f in GD32PinMapGenerator.get_spi_nss_pins(pinmap, device_name): - output += GD32PinMapGenerator.add_standard_af_pin(p, f) + output += GD32PinMapGenerator.exec_by_pin_group( + GD32PinMapGenerator.get_spi_nss_pins(pinmap, device_name), + lambda p, f, context: GD32PinMapGenerator.add_standard_af_pin(p, f, mcu, context)) output += GD32PinMapGenerator.end_pinmap() # CAN RD output += GD32PinMapGenerator.begin_pinmap("CAN_RD") - for p, f in GD32PinMapGenerator.get_can_rd_pins(pinmap, device_name): - output += GD32PinMapGenerator.add_standard_af_pin(p, f) + output += GD32PinMapGenerator.exec_by_pin_group( + GD32PinMapGenerator.get_can_rd_pins(pinmap, device_name), + lambda p, f, context: GD32PinMapGenerator.add_standard_af_pin(p, f, mcu, context)) output += GD32PinMapGenerator.end_pinmap() # CAN TD output += GD32PinMapGenerator.begin_pinmap("CAN_TD") - for p, f in GD32PinMapGenerator.get_can_td_pins(pinmap, device_name): - output += GD32PinMapGenerator.add_standard_af_pin(p, f) + output += GD32PinMapGenerator.exec_by_pin_group( + GD32PinMapGenerator.get_can_td_pins(pinmap, device_name), + lambda p, f, context: GD32PinMapGenerator.add_standard_af_pin(p, f, mcu, context)) output += GD32PinMapGenerator.end_pinmap() # was refactored to be in core since it's constant data. # ports @@ -410,8 +541,8 @@ def generate_arduino_peripheralnames_h(pinmap:GD32PinMap, device_name:str) -> st return output @staticmethod - def generate_arduino_pinnamesvar_h(pinmap:GD32PinMap, device_name:str) -> str: - output = pinnamesvar_h_empty_header + def generate_arduino_pinnamesvar_h(peripheral_pins_output: str) -> str: + output = "".join(m + ",\n" for m in GD32PinMapGenerator.get_all_alt_pins(peripheral_pins_output)) return output @staticmethod @@ -450,7 +581,8 @@ def get_second_or_fallback_first_pin(pins, already_assigned_pins:List[str] = Non return pin_candidate @staticmethod - def generate_arduino_variant_h(pinmap:GD32PinMap, device_name:str) -> str: + def generate_arduino_variant_h(pinmap:GD32PinMap, mcu:GD32MCUInfo, peripheral_c: str) -> str: + device_name = mcu.name_no_package output = community_copyright_header output += variant_h_header_start # generate all "#define " macros @@ -478,6 +610,14 @@ def generate_arduino_variant_h(pinmap:GD32PinMap, device_name:str) -> str: output += GD32PinMapGenerator.add_macro_def("ANALOG_PINS_LAST", all_adc_pins[-1]) else: output += "/* warning: no ADC pins detected.. */\n" + + output += "\n/* alternative pin remappings */\n" + for p in GD32PinMapGenerator.get_all_alt_pins(peripheral_c): + # convert from PORTA_1_ALT1 to PA1_ALT1 + m = re.match("PORT([A-Z])_([0-9]+)_(ALT.)", p) + arduino_pin = f"P{m.group(1)}{m.group(2)}" + output += f"#define {arduino_pin}_{m.group(3)} ({arduino_pin} | {m.group(3)})\n" + output += "\n/* LED definitions */\n" if pinmap.pin_is_available_for_device("PC13", device_name): output += GD32PinMapGenerator.add_macro_def("LED_BUILTIN", "PC13") # default for now @@ -641,40 +781,39 @@ def generate_arduino_ldscript(mcu: GD32MCUInfo) -> str: @staticmethod def print_pinmap_info(pinmap: GD32PinMap): - all_i2c_sda_pins = pinmap.search_pins_for_function(GD32PinMap.CRITERIA_PIN_SUB_FUNCTION, "SDA") + all_i2c_sda_pins = pinmap.search_pins_for_function([GD32PinCriteria(GD32PinCriteriaType.PIN_SUB_FUNCTION, ["SDA"])]) for pin, func in all_i2c_sda_pins: print("Found I2C SDA pin %s (AF%d, func %s, periph %s, footnote %s %s)" % (pin.pin_name, func.af_number, func.signal_name, func.peripheral, func.footnote, func.footnote_resolved)) - all_uart_pins = pinmap.search_pins_for_function(GD32PinMap.CRITERIA_PERIPHERAL_STARTS_WITH, "UART") - all_uart_pins.extend(pinmap.search_pins_for_function(GD32PinMap.CRITERIA_PERIPHERAL_STARTS_WITH, "USART")) + all_uart_pins = pinmap.search_pins_for_function([GD32PinCriteria(GD32PinCriteriaType.PERIPHERAL_STARTS_WITH, ["UART", "USART"])]) for pin, func in all_uart_pins: print("Found UART pin %s (AF%d, func %s, periph %s, footnote %s)" % (pin.pin_name, func.af_number, func.signal_name, func.peripheral, func.footnote)) - all_can_rx_pins = pinmap.search_pins_for_function(GD32PinMap.CRITERIA_PERIPHAL_AND_PIN_SUB_FUNCTION, ("CAN", "RX")) + all_can_rx_pins = pinmap.search_pins_for_function([GD32PinCriteria(GD32PinCriteriaType.PERIPHAL_AND_PIN_SUB_FUNCTION, [("CAN", "RX")])]) for pin, func in all_can_rx_pins: print("Found CAN RX pin %s (AF%d, func %s, periph %s, footnote %s)" % (pin.pin_name, func.af_number, func.signal_name, func.peripheral, func.footnote)) - all_can_pins = pinmap.search_pins_for_function(GD32PinMap.CRITERIA_PERIPHERAL_STARTS_WITH, "CAN") + all_can_pins = pinmap.search_pins_for_function([GD32PinCriteria(GD32PinCriteriaType.PERIPHERAL_STARTS_WITH, ["CAN"])]) for pin, func in all_can_pins: if func.has_af_number(): print("Found CAN pin %s (AF%d, func %s, periph %s, footnote %s)" % (pin.pin_name, func.af_number, func.signal_name, func.peripheral, func.footnote)) else: print("Found CAN pin %s (func %s, periph %s, subseries %s)" % (pin.pin_name, func.signal_name, func.peripheral, func.subseries)) - all_adc_pins = pinmap.search_pins_for_function(GD32PinMap.CRITERIA_PERIPHERAL_STARTS_WITH, "ADC") + all_adc_pins = pinmap.search_pins_for_function([GD32PinCriteria(GD32PinCriteriaType.PERIPHERAL_STARTS_WITH, ["ADC"])]) for pin, func in all_adc_pins: print("Found ADC pin %s (func %s, periph %s, subseries %s)" % (pin.pin_name, func.signal_name, func.peripheral, func.subseries)) print("Testing search for only a device name.") - all_adc_pins = pinmap.search_pins_for_function(GD32PinMap.CRITERIA_PERIPHERAL_STARTS_WITH, "ADC", filter_device_name="GD32F190T6") + all_adc_pins = pinmap.search_pins_for_function([GD32PinCriteria(GD32PinCriteriaType.PERIPHERAL_STARTS_WITH, ["ADC"])], filter_device_name="GD32F190T6") for pin, func in all_adc_pins: print("Found ADC pin %s (func %s, periph %s, subseries %s)" % (pin.pin_name, func.signal_name, func.peripheral, func.subseries)) - all_i2c_sda_pins = pinmap.search_pins_for_function(GD32PinMap.CRITERIA_PIN_SUB_FUNCTION, "SDA", filter_device_name="GD32F190T6") + all_i2c_sda_pins = pinmap.search_pins_for_function([GD32PinCriteria(GD32PinCriteriaType.PIN_SUB_FUNCTION, ["SDA"])], filter_device_name="GD32F190T6") for pin, func in all_i2c_sda_pins: print("Found I2C SDA pin %s (AF%d, func %s, periph %s, footnote %s %s)" % (pin.pin_name, func.af_number, func.signal_name, func.peripheral, func.footnote, func.footnote_resolved)) - all_i2c_sda_pins = pinmap.search_pins_for_function(GD32PinMap.CRITERIA_PIN_SUB_FUNCTION, "SDA", filter_device_name="GD32F190T4") + all_i2c_sda_pins = pinmap.search_pins_for_function([GD32PinCriteria(GD32PinCriteriaType.PIN_SUB_FUNCTION, ["SDA"])], filter_device_name="GD32F190T4") for pin, func in all_i2c_sda_pins: print("Found I2C SDA pin %s (AF%d, func %s, periph %s, footnote %s %s)" % (pin.pin_name, func.af_number, func.signal_name, func.peripheral, func.footnote, func.footnote_resolved)) @@ -694,11 +833,11 @@ def generate_from_pinmap(pinmap: GD32PinMap, mcus:List[GD32MCUInfo]): print_big_str(output) write_to_file(output, path.join(target_base_folder, "PeripheralNames.h")) # PeripheralPins.c - output = GD32PinMapGenerator.generate_arduino_peripheralpins_c(pinmap, mcu_name) - print_big_str(output) - write_to_file(output, path.join(target_base_folder, "PeripheralPins.c")) - # PinNamesVar.h - output = GD32PinMapGenerator.generate_arduino_pinnamesvar_h(pinmap, mcu_name) + peripheral_output = GD32PinMapGenerator.generate_arduino_peripheralpins_c(pinmap, mcu) + print_big_str(peripheral_output) + write_to_file(peripheral_output, path.join(target_base_folder, "PeripheralPins.c")) + # PinNamesVar.h; Attention! Uses PeripheralPins.c output to generate a list of alt names + output = GD32PinMapGenerator.generate_arduino_pinnamesvar_h(peripheral_output) print_big_str(output) write_to_file(output, path.join(target_base_folder, "PinNamesVar.h")) # variant.cpp @@ -706,7 +845,7 @@ def generate_from_pinmap(pinmap: GD32PinMap, mcus:List[GD32MCUInfo]): print_big_str(output) write_to_file(output, path.join(target_base_folder, "variant.cpp")) # variant.h - output = GD32PinMapGenerator.generate_arduino_variant_h(pinmap, mcu_name) + output = GD32PinMapGenerator.generate_arduino_variant_h(pinmap, mcu, peripheral_output) print_big_str(output) write_to_file(output, path.join(target_base_folder, "variant.h")) # ldscript.ld diff --git a/misc/scripts/gd32_genpinmap/preparsed_datasheets/GD32F10x.p b/misc/scripts/gd32_genpinmap/preparsed_datasheets/GD32F10x.p new file mode 100644 index 0000000..172e0f7 Binary files /dev/null and b/misc/scripts/gd32_genpinmap/preparsed_datasheets/GD32F10x.p differ diff --git a/misc/scripts/gd32_genpinmap/static_data.py b/misc/scripts/gd32_genpinmap/static_data.py index 29e7cd5..4106878 100644 --- a/misc/scripts/gd32_genpinmap/static_data.py +++ b/misc/scripts/gd32_genpinmap/static_data.py @@ -28,12 +28,12 @@ OF SUCH DAMAGE. */ -""" - -spl_family_b_peripheral_pins_c_header = """#include "PeripheralPins.h" #include "gd32xxyy.h" +#include "PeripheralPins.h" + +""" -/* void pin_function(PinName pin, int function); +spl_family_b_peripheral_pins_c_header = """/* void pin_function(PinName pin, int function); configure the speed, mode,and remap function of pins the parameter function contains the configuration information,show as below bit 0:2 gpio mode @@ -100,6 +100,68 @@ """ +# Reference wiring_digital.c to see which of the GD32PinMode enums are used +spl_family_a_peripheral_pins_c_header = """/* void pin_function(PinName pin, int function); + configure the speed, mode,and remap function of pins + the parameter function contains the configuration information,show as below + bit 0:2 gpio mode + bit 3:8 remap + bit 9:10 gpio speed + bit 11:15 adc /timer channel +*/ + +/* pin descriptions only reference the index in the array, so + * to get e.g. AF11 one must give it index = 9. provide + * convenience macros here. + * for all other arrays, the value is also equivalent to the index, + * so there doesn't need to be anything done more. + */ + +/* Generated remapping names */ + +const int GD_GPIO_REMAP[] = { + 0x00000000, +#if __has_include("GD32_FAMILY_REMAP_HEADER") +#define __REMAP_NAME__(remap) GPIO_ ## remap, +#include "GD32_FAMILY_REMAP_HEADER" +#undef __REMAP_NAME__ +#endif +}; + +enum GD_GPIO_REMAP_NAME { + REMAP_NONE = 0U, +#if __has_include("gd32f10x_remap.h") +#define __REMAP_NAME__(remap) remap, +#include "GD32_FAMILY_REMAP_HEADER" +#undef __REMAP_NAME__ +#define __REMAP_NAME__(remap) DISABLE_ ## remap = GPIO_ ## remap | (1U << 6), +#include "GD32_FAMILY_REMAP_HEADER" +#undef __REMAP_NAME__ +#endif +}; + +/* GPIO MODE */ +const int GD_GPIO_MODE[] = { + GPIO_MODE_AIN, /* 0 INPUT_ANALOG */ + GPIO_MODE_IN_FLOATING, /* 1 INPUT */ + GPIO_MODE_IPD, /* 2 INPUT_PULLDOWN */ + GPIO_MODE_IPU, /* 3 INPUT_PULLUP */ + GPIO_MODE_OUT_OD, /* 4 OUTPUT_OPEN_DRAIN */ + GPIO_MODE_OUT_PP, /* 5 OUTPUT */ + 0, /* 6 (unused) */ + 0, /* 7 (unused) */ +}; + +/* GPIO SPEED */ +const int GD_GPIO_SPEED[] = { + GPIO_OSPEED_2MHZ, /* 0 */ + GPIO_OSPEED_10MHZ, /* 1 */ + 0, /* 2 (unused) */ + GPIO_OSPEED_50MHZ, /* 3 */ +}; + +""" + community_copyright_header = """/* Copyright (c) 2021, CommunityGD32Cores @@ -148,9 +210,12 @@ #endif """ -pinnamesvar_h_empty_header = """#ifndef _PINNAMESVAR_H_ +pinnamesvar_h_header_start = """#ifndef _PINNAMESVAR_H_ #define _PINNAMESVAR_H_ +""" + +pinnamesvar_h_header_end = """ #endif /* _PINNAMESVAR_H_ */""" variant_h_header_start = """#ifndef _VARIANT_