Tool/software:
Hello,
I have 2 lines of code written in DriverLib mode, as shown below:
GPIO_setPinConfig(GPIO_4_GPIO4);
GPIO_writePin(4,0);
If they are re-written in Bit Field / Register-Level Mode, what will they be?
Thanks!
The lines below are written in DriverLib mode:
GPIO_setPinConfig(GPIO_4_GPIO4);
GPIO_setPinConfig(GPIO_5_GPIO5);
GPIO_setPinConfig(GPIO_6_GPIO6);
GPIO_setPinConfig(GPIO_7_GPIO7);
GPIO_writePin(4,0);
GPIO_writePin(5,0);
GPIO_writePin(6,0);
GPIO_writePin(7,0);
I converted the lines above to Register Mode by using HWREGH macro, but they do NOT work the same way at the lines above:
EALLOW;
// Configure GPIO4–GPIO7 as GPIOs (Clear corresponding bits in GPAMUX1)
HWREGH(0x00007C42) &= ~(0xFF << 8); // Clear bits 15-8 (GPIO4–GPIO7)
// Set GPIO4–GPIO7 as outputs (Set bits 4–7 in GPADIR)
HWREGH(0x00007C4A) |= (0xF << 4); // Set bits 4–7
EDIS;
// Set GPIO4–GPIO7 output to LOW (Clear bits 4–7 in GPACLEAR)
HWREGH(0x00007C2A) = (0xF << 4);
Please advise what the equivalent Bit Field / Register-Level Mode code are. Thanks!
Is there an application note or article that provides step-by-step guidance on converting DriverLib code to Bit Field code?
Hello,
Here is how I would suggest to write on a specific GPIO:
//
// Enable an GPIO output on GPIO6, set it high
//
GpioCtrlRegs.GPAPUD.bit.GPIO6 = 0; // Enable pullup on GPIO6
GpioDataRegs.GPASET.bit.GPIO6 = 1; // Load output latch
GpioCtrlRegs.GPAMUX1.bit.GPIO6 = 0; // GPIO6 = GPIO6
GpioCtrlRegs.GPADIR.bit.GPIO6 = 1; // GPIO6 = output
You can refer to C2000ware for C2000Warexx\device_support\f28002x\examples\gpio to find some examples.
Best Regards,
Masoud
Thanks. Please see below:
GPIO_setPinConfig(GPIO_4_GPIO4);
GPIO_setPinConfig(GPIO_5_GPIO5);
GPIO_setPinConfig(GPIO_6_GPIO6);
GPIO_setPinConfig(GPIO_7_GPIO7);
GPIO_writePin(4,0);
GPIO_writePin(5,0);
GPIO_writePin(6,0);
GPIO_writePin(7,0);
Hello Quentin,
To answer your first question, we unfortunately do not have any application notes or articles that cover DriverLib to Bit Field code conversion. However, you can include and use both DriverLib and Bit Field code in the same file to take advantage of both APIs. For more info for setting this approach up, see Section 2.3 in the file located at C:/ti/c2000/C2000Ware_<version>/device_support/f28002x/docs/F28002x_FRM_EX_UG.pdf
In order to convert your DriverLib code to the Bit Field code you are requesting, I would advise using the GpioCtrlRegs.GPAxxx.all
approach. See the code below:
// Enable pullup on GPIO 4-7 GpioCtrlRegs.GPAPUD.all &= ~((1 << 4) | (1 << 5) | (1 << 6) | (1 << 7)); // Clear Data Regs for GPIO 4-7 GpioDataRegs.GPACLEAR.all |= (1 << 4) | (1 << 5) | (1 << 6) | (1 << 7); // Set up mux for GPIO 4-7 and set GPIO 4-7 to output GpioCtrlRegs.GPAMUX1.all |= (1 << 4) | (1 << 5) | (1 << 6) | (1 << 7); GpioCtrlRegs.GPADIR.all |= (1 << 4) | (1 << 5) | (1 << 6) | (1 << 7);
Best,
Ryan