TMC7300
Loading...
Searching...
No Matches
TMC_Field.h
Go to the documentation of this file.
1#ifndef TMC_FIELD_H
2#define TMC_FIELD_H
3
4#include <Arduino.h>
5
6// modified from https://github.com/bread-wolf/TMCField/blob/8f3a6262acd8b2a699c473451a84f5d03436e87d/TMCField.hpp#L13C1-L41C3
7class TMCField {
8public:
9 /* Class constructor, initializes private attributes. */
10 TMCField(uint32_t _address, uint32_t _mask, uint32_t _shift, uint32_t _valueAddress)
11 : mask(_mask)
12 , addr(_address)
13 , shift(_shift)
14 , valueAddr(_valueAddress)
15 {
16 }
17
18 /* Sets fieldValue inside registerValue. */
19 inline uint32_t setField(uint32_t fieldValue, uint32_t registerValue)
20 {
21 return (registerValue & (~mask)) | ((fieldValue << shift) & mask);
22 }
23
24 /* Extracts the value of the field from registerValue. */
25 inline uint32_t getField(uint32_t registerValue)
26 {
27 return (registerValue & mask) >> shift;
28 }
29
30 /* Gets address of register that contains this field. */
31 inline uint32_t address()
32 {
33 return addr;
34 }
35 inline uint32_t valueAddress()
36 {
37 return valueAddr;
38 }
39
40private:
41 const uint32_t mask, addr;
42 const uint8_t shift;
43 const uint32_t valueAddr;
44};
45
46#endif // TMC_FIELD_H
Definition TMC_Field.h:7
TMCField(uint32_t _address, uint32_t _mask, uint32_t _shift, uint32_t _valueAddress)
Definition TMC_Field.h:10
uint32_t address()
Definition TMC_Field.h:31
uint32_t getField(uint32_t registerValue)
Definition TMC_Field.h:25
uint32_t setField(uint32_t fieldValue, uint32_t registerValue)
Definition TMC_Field.h:19
uint32_t valueAddress()
Definition TMC_Field.h:35