Revision | 31 (tree) |
---|---|
Zeit | 2019-09-15 02:38:15 |
Autor | ![]() |
- Documentação atualizada
@@ -11,7 +11,7 @@ | ||
11 | 11 | type |
12 | 12 | TCustomPasRipherals = class; |
13 | 13 | |
14 | - { TPRSavedState } | |
14 | + { TSavedState } | |
15 | 15 | |
16 | 16 | //: Este record é usado pela propriedade @Link(TCustomPasRipherals.State) e |
17 | 17 | //: representa os estados de todos os registradores do RPI. Os nomes dos |
@@ -50,14 +50,14 @@ | ||
50 | 50 | //: @Member(GPLEV0 Este membro representa o registrador GPLEV0, o qual |
51 | 51 | //: contém o primeiro conjunto de campos de níveis lógicos dos GPIO, |
52 | 52 | //: abrangendo os GPIO de 0 a 31, ou seja, cada bit representa o estado de um |
53 | - //: GPIO. Caso o bit seja 0, o valor do nível lógico é zero e caso seja um o | |
53 | + //: GPIO. Caso o bit seja 0, o valor do nível lógico é zero e caso seja 1, o | |
54 | 54 | //: valor do nível lógio é 1) |
55 | 55 | //: @Member(GPLEV1 Este membro representa o registrador GPLEV1, o qual |
56 | 56 | //: contém o segundo conjunto de campos de níveis lógicos dos GPIO, |
57 | 57 | //: abrangendo os GPIO de 32 a 53, ou seja, cada bit representa o estado de um |
58 | - //: GPIO. Caso o bit seja 0, o valor do nível lógico é zero e caso seja um o | |
58 | + //: GPIO. Caso o bit seja 0, o valor do nível lógico é zero e caso seja 1, o | |
59 | 59 | //: valor do nível lógio é 1) |
60 | - TPRSavedState = record | |
60 | + TSavedState = record | |
61 | 61 | GPFSEL0: UInt32; |
62 | 62 | GPFSEL1: UInt32; |
63 | 63 | GPFSEL2: UInt32; |
@@ -68,38 +68,39 @@ | ||
68 | 68 | GPLEV1: UInt32; |
69 | 69 | end; |
70 | 70 | |
71 | - //: Este subtipo define um range que varia de 0 a 53 e que serve para | |
72 | - //: representar cada um dos 54 GPIOs disponíveis no Raspberry PI 3 (segundo o | |
73 | - //: datasheet do BCM2837). | |
74 | - TPRGPIONumber = 0..53; | |
75 | - //: Este subtipo define um range que varia de 0 a 27 e que serve para | |
76 | - //: representar os 28 primeiros GPIOs que possuem um pino físico associado. | |
77 | - //: Este subtipo pode ser usado em loops ou funções quando se quer limitar o | |
78 | - //: acesso a apenas os pinos que são manipuláveis externamente | |
79 | - TPRGPIONumberExposed = 0..27; | |
80 | - //: Este subtipo representa os 40 pinos físicos do RPI. O Raspberry PI 3 expõe | |
71 | + //: Este tipo define um subconjunto de números que variam de 0 a 53 e que | |
72 | + //: serve para representar cada um dos 54 GPIOs disponíveis no Raspberry PI 3 | |
73 | + //: (segundo o datasheet do BCM2837). | |
74 | + TGPIONumber = 0..53; | |
75 | + //: Este tipo define um subconjunto de números que variam de 0 a 27 e que | |
76 | + //: serve para representar os 28 primeiros GPIOs que possuem um pino físico | |
77 | + //: associado. Este tipo pode ser usado em loops ou funções quando se quer | |
78 | + //: limitar o acesso a apenas os pinos que são manipuláveis externamente | |
79 | + TGPIONumberExposed = 0..27; | |
80 | + //: Este tipo representa os 40 pinos físicos do RPI. O Raspberry PI 3 expõe | |
81 | 81 | //: 40 pinos físicos e destes, apenas 28 estão efetivamente associados a algum |
82 | 82 | //: GPIO. Os outros 12 pinos físicos contém GND e saídas de 5v e 3.3v. |
83 | - //: @SeeAlso(TPRGPIONumberExposed) | |
84 | - TPRGPIOPhysicalPinNumber = 1..40; | |
83 | + //: @SeeAlso(TGPIONumberExposed) | |
84 | + TGPIOPhysicalPinNumber = 1..40; | |
85 | 85 | //: Esta enumeração lista todos os possíveis modos dos GPIOs. Cada GPIO pode |
86 | 86 | //: ter até seis funções alternativas além de entrada e saída. As funções |
87 | 87 | //: alternativas Alt0 a Alt5 dependem de cada GPIO e a tabela nas páginas 102 |
88 | 88 | //: e 103 do datasheet mostram cada uma delas. |
89 | - //: @value(prgmInput Um GPIO está neste modo para poder aceitar entrada de | |
89 | + //: @value(gmInput Um GPIO está neste modo para poder aceitar entrada de | |
90 | 90 | //: dados (níveis lógicos)) |
91 | - //: @value(prgmOutput Um GPIO está neste modo para prover saída de deados | |
91 | + //: @value(gmOutput Um GPIO está neste modo para prover saída de deados | |
92 | 92 | //: (níveis lógicos)) |
93 | - //: @value(prgmAlt0 Habilita o modo alternativo 0 para o GPIO) | |
94 | - //: @value(prgmAlt1 Habilita o modo alternativo 1 para o GPIO) | |
95 | - //: @value(prgmAlt2 Habilita o modo alternativo 2 para o GPIO) | |
96 | - //: @value(prgmAlt3 Habilita o modo alternativo 3 para o GPIO) | |
97 | - //: @value(prgmAlt4 Habilita o modo alternativo 4 para o GPIO) | |
98 | - //: @value(prgmAlt5 Habilita o modo alternativo 5 para o GPIO) | |
99 | - TPRGPIOMode = (prgmInput,prgmOutput,prgmAlt5,prgmAlt4,prgmAlt0,prgmAlt1,prgmAlt2,prgmAlt3); | |
100 | - //: Este subtipo define um range fixo de 0 a 5, o qual é usado nas funções que | |
101 | - //: manipuluam os registradores GPFSEL. Existem seis registradores GPFSEL, | |
102 | - //: numerados de 0 a 5, dentre os conjuntos de registradores de GPIO | |
93 | + //: @value(gmAlt0 Habilita o modo alternativo 0 para o GPIO em questão) | |
94 | + //: @value(gmAlt1 Habilita o modo alternativo 1 para o GPIO em questão) | |
95 | + //: @value(gmAlt2 Habilita o modo alternativo 2 para o GPIO em questão) | |
96 | + //: @value(gmAlt3 Habilita o modo alternativo 3 para o GPIO em questão) | |
97 | + //: @value(gmAlt4 Habilita o modo alternativo 4 para o GPIO em questão) | |
98 | + //: @value(gmAlt5 Habilita o modo alternativo 5 para o GPIO em questão) | |
99 | + TGPIOMode = (gmInput,gmOutput,gmAlt5,gmAlt4,gmAlt0,gmAlt1,gmAlt2,gmAlt3); | |
100 | + //: Este tipo define um subconjunto numérico fixo de 0 a 5, o qual é usado nas | |
101 | + //: funções que manipuluam os registradores GPFSEL. Existem seis registradores | |
102 | + //: GPFSEL, numerados de 0 a 5, dentre os conjuntos de registradores de GPIO. | |
103 | + //: @SeeAlso(TGPIOMode) | |
103 | 104 | TPRGPIOModeBank = 0..5; |
104 | 105 | //: Esta enumeração representa os possíveis estados dos "resistores pull" |
105 | 106 | //: associados a cada GPIO. Cada GPIO possui um "resitor pull" que serve para |
@@ -154,7 +155,7 @@ | ||
154 | 155 | //: @member(Level Obtém ou configura o nível lógico do GPIO atual) |
155 | 156 | TPRGPIO = record |
156 | 157 | private |
157 | - FGPIONumber: TPRGPIONumber; | |
158 | + FGPIONumber: TGPIONumber; | |
158 | 159 | FPasRipherals: TCustomPasRipherals; |
159 | 160 | |
160 | 161 | // ------------------------------------------------------------------------- |
@@ -220,12 +221,12 @@ | ||
220 | 221 | |
221 | 222 | function GetModeDescription: String; |
222 | 223 | function GetLevel: TPRGPIOLevel; |
223 | - function GetMode: TPRGPIOMode; | |
224 | + function GetMode: TGPIOMode; | |
224 | 225 | procedure SetLevel(AGPIOLevel: TPRGPIOLevel); |
225 | - procedure SetMode(AGPIOMode: TPRGPIOMode); | |
226 | + procedure SetMode(AGPIOMode: TGPIOMode); | |
226 | 227 | procedure SetPullRegister(AGPIOPullRegister: TPRGPIOPullRegister); |
227 | 228 | public |
228 | - property Mode: TPRGPIOMode read GetMode write SetMode; | |
229 | + property Mode: TGPIOMode read GetMode write SetMode; | |
229 | 230 | property PullRegister: TPRGPIOPullRegister write SetPullRegister; |
230 | 231 | property ModeDescription: String read GetModeDescription; |
231 | 232 | property Level: TPRGPIOLevel read GetLevel write SetLevel; |
@@ -735,18 +736,18 @@ | ||
735 | 736 | FRunningAsRoot: Boolean; |
736 | 737 | |
737 | 738 | function GetClock(AClockId: TPRClockId): TPRClock; |
738 | - function GetGPIO(AGPIONumber: TPRGPIONumber): TPRGPIO; | |
739 | + function GetGPIO(AGPIONumber: TGPIONumber): TPRGPIO; | |
739 | 740 | function GetPWM(APWMChannel: TPRPWMChannel): TPRPWM; |
740 | 741 | function GetI2C(AController: TPRI2CController; ASlaveAddress: TPRI2CSlaveAddress): TPRI2C; |
741 | 742 | |
742 | 743 | function GetLevels(ALevelBank: TPRGPIOLevelBank): UInt32; |
743 | 744 | function GetModes(AModeBank: TPRGPIOModeBank): UInt32; |
744 | - function GetState: TPRSavedState; | |
745 | + function GetState: TSavedState; | |
745 | 746 | function GetInfo: String; |
746 | 747 | |
747 | 748 | procedure SetLevels(ALevelBank: TPRGPIOLevelBank; ALevels: UInt32); |
748 | 749 | procedure SetModes(AModeBank: TPRGPIOModeBank; AModes: UInt32); |
749 | - procedure SetState(ASavedState: TPRSavedState); | |
750 | + procedure SetState(ASavedState: TSavedState); | |
750 | 751 | |
751 | 752 | function ClockBaseAddress: PUInt32; |
752 | 753 | function GPIOBaseAddress: PUInt32; |
@@ -770,12 +771,12 @@ | ||
770 | 771 | procedure SetBitsValue(ARegister: PUInt32; AValue: UInt32; ABitIndex: UInt8; ABitsCount: UInt8 = 1); |
771 | 772 | |
772 | 773 | property Clock[AClockId: TPRClockId]: TPRClock read GetClock; |
773 | - property GPIO[AGPIONumber: TPRGPIONumber]: TPRGPIO read GetGPIO; | |
774 | + property GPIO[AGPIONumber: TGPIONumber]: TPRGPIO read GetGPIO; | |
774 | 775 | property PWM[APWMChannel: TPRPWMChannel]: TPRPWM read GetPWM; |
775 | 776 | property I2C[AController: TPRI2CController; ASlaveAddress: TPRI2CSlaveAddress]: TPRI2C read GetI2C; |
776 | 777 | property GPIOLevels[ALevelBank: TPRGPIOLevelBank]: UInt32 read GetLevels write SetLevels; |
777 | 778 | property GPIOModes[AModeBank: TPRGPIOModeBank]: UInt32 read GetModes write SetModes; |
778 | - property State: TPRSavedState read GetState write SetState; | |
779 | + property State: TSavedState read GetState write SetState; | |
779 | 780 | property Info: String read GetInfo; |
780 | 781 | public |
781 | 782 | constructor Create; virtual; |
@@ -786,17 +787,17 @@ | ||
786 | 787 | //: número do GPIO correspondente) |
787 | 788 | //: @Returns(Retorna o número do GPIO correspondente ao número do pino |
788 | 789 | //: físico informado no parâmetro) |
789 | - //: @SeeAlso(TPRGPIOPhysicalPinNumber) | |
790 | - //: @SeeAlso(TPRGPIONumber) | |
791 | - function P2G(APhysicalPinNumber: TPRGPIOPhysicalPinNumber): TPRGPIONumber; | |
790 | + //: @SeeAlso(TGPIOPhysicalPinNumber) | |
791 | + //: @SeeAlso(TGPIONumber) | |
792 | + function P2G(APhysicalPinNumber: TGPIOPhysicalPinNumber): TGPIONumber; | |
792 | 793 | //: Retorna o número do pino físico correspondente ao GPIO informado |
793 | 794 | //: @Param(AGPIONumber Número do GPIO a partir do qual se quer saber o |
794 | 795 | //: número do pino físico correspondente) |
795 | 796 | //: @Returns(Retorna o número do pino físico correspondente ao número do |
796 | 797 | //: GPIO informado no parâmetro) |
797 | - //: @SeeAlso(TPRGPIOPhysicalPinNumber) | |
798 | - //: @SeeAlso(TPRGPIONumber) | |
799 | - function G2P(AGPIONumber: TPRGPIONumber): TPRGPIOPhysicalPinNumber; | |
798 | + //: @SeeAlso(TGPIOPhysicalPinNumber) | |
799 | + //: @SeeAlso(TGPIONumber) | |
800 | + function G2P(AGPIONumber: TGPIONumber): TGPIOPhysicalPinNumber; | |
800 | 801 | end; |
801 | 802 | |
802 | 803 | //: Esta é a classe principal do PasRipherals. Instancie-a para ter acesso aos |
@@ -1732,7 +1733,7 @@ | ||
1732 | 1733 | |
1733 | 1734 | { TPRGPIO } |
1734 | 1735 | |
1735 | -function TPRGPIO.GetMode: TPRGPIOMode; | |
1736 | +function TPRGPIO.GetMode: TGPIOMode; | |
1736 | 1737 | var |
1737 | 1738 | Shift: UInt8; |
1738 | 1739 | begin |
@@ -1824,7 +1825,7 @@ | ||
1824 | 1825 | |
1825 | 1826 | function TPRGPIO.GetModeDescription: String; |
1826 | 1827 | const |
1827 | - ALTERNATETIVE_FUNCTION_NAMES: array [TPRGPIOModeBank] of array [TPRGPIONumber] of String = | |
1828 | + ALTERNATETIVE_FUNCTION_NAMES: array [TPRGPIOModeBank] of array [TGPIONumber] of String = | |
1828 | 1829 | // ALT0 |
1829 | 1830 | (('I2C SDA0','I2C SCL0','I2C SDA1','I2C SCL1','GPCLK0','GPCLK1','GPCLK2','SPI0 CE1/' |
1830 | 1831 | ,'SPI0 CE0/','SPI0 MISO','SPI0 MOSI','SPI0 SCLK','PWM0','PWM1','TxD0','RxD0' |
@@ -1890,7 +1891,7 @@ | ||
1890 | 1891 | Result := TPRGPIOLevel((RegisterGPLEV^ and RegisterBitValue) shr RegisterBitIndex); |
1891 | 1892 | end; |
1892 | 1893 | |
1893 | -procedure TPRGPIO.SetMode(AGPIOMode: TPRGPIOMode); | |
1894 | +procedure TPRGPIO.SetMode(AGPIOMode: TGPIOMode); | |
1894 | 1895 | var |
1895 | 1896 | Shift: UInt8; |
1896 | 1897 | begin |
@@ -1939,7 +1940,7 @@ | ||
1939 | 1940 | Result.FClockId := AClockId; |
1940 | 1941 | end; |
1941 | 1942 | |
1942 | -function TCustomPasRipherals.GetGPIO(AGPIONumber: TPRGPIONumber): TPRGPIO; | |
1943 | +function TCustomPasRipherals.GetGPIO(AGPIONumber: TGPIONumber): TPRGPIO; | |
1943 | 1944 | begin |
1944 | 1945 | Result.FPasRipherals := Self; |
1945 | 1946 | Result.FGPIONumber := AGPIONumber; |
@@ -2186,7 +2187,7 @@ | ||
2186 | 2187 | NanoSleep(1000 * AMicroSeconds); |
2187 | 2188 | end; |
2188 | 2189 | |
2189 | -function TCustomPasRipherals.P2G(APhysicalPinNumber: TPRGPIOPhysicalPinNumber): TPRGPIONumber; | |
2190 | +function TCustomPasRipherals.P2G(APhysicalPinNumber: TGPIOPhysicalPinNumber): TGPIONumber; | |
2190 | 2191 | begin |
2191 | 2192 | case APhysicalPinNumber of |
2192 | 2193 | 27: Result := 0; |
@@ -2222,7 +2223,7 @@ | ||
2222 | 2223 | end; |
2223 | 2224 | end; |
2224 | 2225 | |
2225 | -function TCustomPasRipherals.G2P(AGPIONumber: TPRGPIONumber): TPRGPIOPhysicalPinNumber; | |
2226 | +function TCustomPasRipherals.G2P(AGPIONumber: TGPIONumber): TGPIOPhysicalPinNumber; | |
2226 | 2227 | begin |
2227 | 2228 | case AGPIONumber of |
2228 | 2229 | 00: Result := 27; |
@@ -2258,9 +2259,9 @@ | ||
2258 | 2259 | end; |
2259 | 2260 | end; |
2260 | 2261 | |
2261 | -function TCustomPasRipherals.GetState: TPRSavedState; | |
2262 | +function TCustomPasRipherals.GetState: TSavedState; | |
2262 | 2263 | begin |
2263 | - Result := Default(TPRSavedState); | |
2264 | + Result := Default(TSavedState); | |
2264 | 2265 | |
2265 | 2266 | with Result do |
2266 | 2267 | begin |
@@ -2281,7 +2282,7 @@ | ||
2281 | 2282 | const |
2282 | 2283 | INFOLINE = '║ %-11u ║ %-19s ║ %-6s ║ %-14s ║ %-11s ║'; |
2283 | 2284 | var |
2284 | - G: TPRGPIONumber; | |
2285 | + G: TGPIONumber; | |
2285 | 2286 | M: String; |
2286 | 2287 | A: UInt32; |
2287 | 2288 | S: UInt32; |
@@ -2296,7 +2297,7 @@ | ||
2296 | 2297 | Result += '║ GPIO NUMBER ║ PHYSICAL PIN NUMBER ║ MODE ║ NAME ║ LOGIC LEVEL ║'#13#10; |
2297 | 2298 | Result += '╠═════════════╬═════════════════════╬════════╬════════════════╬═════════════╣'#13#10; |
2298 | 2299 | |
2299 | - for G := Low(TPRGPIONumber) to High(TPRGPIONumber) do | |
2300 | + for G := Low(TGPIONumber) to High(TGPIONumber) do | |
2300 | 2301 | begin |
2301 | 2302 | case GPIO[G].Mode of |
2302 | 2303 | prgmAlt0: M := 'ALT0'; |
@@ -2363,12 +2364,12 @@ | ||
2363 | 2364 | end; |
2364 | 2365 | end; |
2365 | 2366 | |
2366 | -procedure TCustomPasRipherals.SetState(ASavedState: TPRSavedState); | |
2367 | +procedure TCustomPasRipherals.SetState(ASavedState: TSavedState); | |
2367 | 2368 | begin |
2368 | 2369 | // Compara o valor padrão do record com o parâmetro para saber se foi |
2369 | 2370 | // informado um valor válido. Aparentemente CompareMem não funciona bem com |
2370 | 2371 | // shortstrings, então, tenha cuidado; |
2371 | - if CompareMem(@Default(TPRSavedState),@ASavedState,SizeOf(TPRSavedState)) then | |
2372 | + if CompareMem(@Default(TSavedState),@ASavedState,SizeOf(TSavedState)) then | |
2372 | 2373 | raise EPasRipherals.Create('Não é possível configurar o estado usando parâmetros vazios') |
2373 | 2374 | else |
2374 | 2375 | with ASavedState do |