tm4c_hal/sysctl.rs
1//! Code for the System Control module.
2
3use crate::time::Hertz;
4
5/// Frozen clock frequencies
6///
7/// The existence of this value indicates that the clock configuration can no longer be changed
8#[derive(Clone, Copy)]
9pub struct Clocks {
10 /// System oscillator clock speed
11 pub osc: Hertz,
12 /// System clock speed
13 pub sysclk: Hertz,
14}
15
16#[derive(Copy, Clone)]
17/// Select in which mode the peripheral should be affected
18pub enum RunMode {
19 /// Run mode
20 Run,
21 /// Sleep mode (i.e. WFI is being executed)
22 Sleep,
23 /// Deep-Sleep mode (i.e. WFI is being executed with SLEEP DEEP bit set)
24 DeepSleep,
25}
26
27#[derive(Copy, Clone)]
28/// Select whether the peripheral should be on or off
29pub enum PowerState {
30 /// Turn peripheral clocks/power off
31 Off,
32 /// Turn peripheral clocks/power on
33 On,
34}
35
36impl Clocks {
37 /// Returns the frequency of the oscillator.
38 pub fn osc(self) -> Hertz {
39 self.osc
40 }
41
42 /// Returns the system (core) frequency
43 pub fn sysclk(self) -> Hertz {
44 self.sysclk
45 }
46}
47
48/// This module is all about identifying the physical chip we're running on.
49pub mod chip_id {
50
51 /// Possible errors we can get back when parsing the ID registers.
52 #[derive(Debug)]
53 pub enum Error {
54 /// Unknown value in DID0
55 UnknownDid0Ver(u8),
56 /// Unknown value in DID1
57 UnknownDid1Ver(u8),
58 }
59
60 /// What sort of device is this?
61 #[derive(Debug)]
62 pub enum DeviceClass {
63 /// It's a Stellaris LM4F or a TM4C123 (they have the same value)
64 StellarisBlizzard,
65 /// It's a "Tiva™ Snowflake-class microcontroller"
66 Snowflake,
67 /// I don't know what chip this is
68 Unknown,
69 }
70
71 /// How many pins on this chip's package?
72 #[derive(Debug)]
73 pub enum PinCount {
74 /// It's a 28 pin package
75 _28,
76 /// It's a 48 pin package
77 _48,
78 /// It's a 100 pin package
79 _100,
80 /// It's a 64 pin package
81 _64,
82 /// It's a 144 pin package
83 _144,
84 /// It's a 157 pin package
85 _157,
86 /// It's a 168 pin package (TM4C123 only)
87 _168,
88 /// I don't know what chip this is
89 Unknown,
90 }
91
92 /// What temperature range does this chip support?
93 #[derive(Debug)]
94 pub enum TempRange {
95 /// It's a Commercial temperature range part (0°C - +70°C)
96 Commercial,
97 /// It's a Industrial temperature range part (-40°C - +85°C)
98 Industrial,
99 /// It's a Extended temperature range part (-40°C - +105°C)
100 Extended,
101 /// It's either Extended or Industrial depending on the exact part
102 /// number
103 IndustrialOrExtended,
104 /// I don't know what temperature range this is
105 Unknown,
106 }
107
108 /// What package is this chip in?
109 #[derive(Debug)]
110 pub enum Package {
111 /// It's a SOIC package
112 Soic,
113 /// It's a LQFP package
114 Lqfp,
115 /// It's a BGA package
116 Bga,
117 /// I don't know what package this is
118 Unknown,
119 }
120
121 /// Is this an experimental chip or a production part?
122 #[derive(Debug)]
123 pub enum Qualification {
124 /// It's a Engineering Sample chip
125 EngineeringSample,
126 /// It's a Pilot Production chip
127 PilotProduction,
128 /// It's a Fully Qualified chip
129 FullyQualified,
130 /// I don't know what qualification this is
131 Unknown,
132 }
133
134 /// These values describe the part number
135 #[derive(Debug)]
136 pub enum PartNo {
137 /// It's a TM4C123GH6PM
138 Tm4c123gh6pm,
139 /// It's a LM4F120H5QR
140 Lm4f120h5qr,
141 /// It's a TM4C1294NCPDT
142 Tm4c1294ncpdt,
143 /// It's a TM4C129ENCPDT
144 Tm4c129encpdt,
145 /// It's an unknown chip - please file a bug report
146 Unknown(u8),
147 }
148
149 /// These values describe the physical LM4F/TM4C chip
150 #[derive(Debug)]
151 pub struct ChipId {
152 /// The device class
153 pub device_class: DeviceClass,
154 /// The major revision
155 pub major: u8,
156 /// The minor revision
157 pub minor: u8,
158 /// The chip's pin count
159 pub pin_count: PinCount,
160 /// The chip's temperature range
161 pub temp_range: TempRange,
162 /// The chip's package
163 pub package: Package,
164 /// True if the chip is RoHS compliant
165 pub rohs_compliant: bool,
166 /// The chip's qualification
167 pub qualification: Qualification,
168 /// The chip's part number
169 pub part_no: PartNo,
170 }
171}