Skip to content

Commit

Permalink
Support Orange Pi 3 Plus
Browse files Browse the repository at this point in the history
  • Loading branch information
liu1313277 authored and orangepi-xunlong committed Oct 27, 2023
1 parent 139296b commit 69d7f1b
Show file tree
Hide file tree
Showing 5 changed files with 1,167 additions and 321 deletions.
78 changes: 54 additions & 24 deletions examples/pwm.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,39 @@
#include<wiringPi.h>
#include <wiringPi.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

extern int OrangePiModel;
extern void sunxi_pwm_set_enable(int en);

typedef struct {
unsigned int arr;
unsigned int div;
unsigned int ccr;
} pwm_info;

static pwm_info pwm_info_t;

static void set_pwm_info(int OrangePiModel)
{
switch (OrangePiModel)
{
case PI_MODEL_ZERO_2:
case PI_MODEL_ZERO_2_W:
pwm_info_t.arr = 1024;
pwm_info_t.div = 1;
pwm_info_t.ccr = 512;
break;
case PI_MODEL_3_PLUS:
pwm_info_t.arr = 1000;
pwm_info_t.div = 120;
pwm_info_t.ccr = 500;
break;
default:
break;
}
}

int main(int argc, char *argv [])
{
int i = 0;
Expand All @@ -16,7 +47,7 @@ int main(int argc, char *argv [])

pin = (unsigned int)strtoul (argv [1], NULL, 10) ;

if (pin != 3 && pin != 4 && pin != 21 && pin != 22 && pin != 2 && pin != 9 ) {
if (pin != 3 && pin != 4 && pin != 21 && pin != 22 && pin != 2 && pin != 9 && pin != 16) {
fprintf (stderr, "the pin you choose doesn't support hardware PWM\n") ;
exit (1) ;
}
Expand All @@ -26,62 +57,62 @@ int main(int argc, char *argv [])

wiringPiSetup();
pinMode(pin,PWM_OUTPUT);
set_pwm_info(OrangePiModel);

printf("wiringPiSetup end\n");

// 开始测试
while(1)
{
pwmSetRange(pin,1024);
pwmSetClock(pin,1);
pwmWrite(pin,512);
while(1) {
pwmSetRange(pin,pwm_info_t.arr);
pwmSetClock(pin,pwm_info_t.div);
pwmWrite(pin,pwm_info_t.ccr);

//1. 调节PWM占空比
//1.1 通过设置ARR调节PWM占空比
printf("Modified ARR test start\n");

for (i = 0 ; i <= 8 ; i++) {
pwmSetRange(pin,1024+i*128);
pwmSetRange(pin,pwm_info_t.arr + i * (pwm_info_t.arr / 8));
delay(500);
}

delay(5000);

for (i = 7 ; i >= 0 ; i-- ) {
pwmSetRange(pin,1024+i*128);
pwmSetRange(pin,pwm_info_t.arr + i * (pwm_info_t.arr / 8));
delay(500);
}

delay(5000);

printf("Modified ARR test end\n");

pwmSetMode(pin,PWM_MODE_BAL);
sunxi_pwm_set_enable(0);
delay(5000);
pwmSetMode(pin,PWM_MODE_MS);
sunxi_pwm_set_enable(1);

//1.2 通过设置CRR调节PWM占空比
printf("Modified CRR test start\n");
//1.2 通过设置CCR调节PWM占空比
printf("Modified CCR test start\n");

for (i = 0 ; i <= 8 ; i++) {
pwmWrite(pin,512 + i*64);
pwmWrite(pin,pwm_info_t.ccr + i * (pwm_info_t.ccr / 8));
delay(500);
}

delay(5000);

for (i = 7 ; i >= 0 ; i-- ) {
pwmWrite(pin,512 + i*64);
pwmWrite(pin,pwm_info_t.ccr + i * (pwm_info_t.ccr / 8));
delay(500);
}

delay(5000);

printf("Modified active range test end\n");
printf("Modified CCR test end\n");

pwmSetMode(pin,PWM_MODE_BAL);
sunxi_pwm_set_enable(0);
delay(5000);
pwmSetMode(pin,PWM_MODE_MS);
sunxi_pwm_set_enable(1);

//2.调节PWM频率
//2.1通过设置分频系数调节PWM频率
Expand All @@ -104,25 +135,24 @@ int main(int argc, char *argv [])

printf("Modified frequency division test end\n");

pwmSetMode(pin,PWM_MODE_BAL);
sunxi_pwm_set_enable(0);
delay(5000);
pwmSetMode(pin,PWM_MODE_MS);
sunxi_pwm_set_enable(1);

//2.2 直接设置PWM频率
printf("Modified PWM frequency test start\n");

for (i = 1 ; i <= 10; i++) {
pwmToneWrite(pin,2000*i);
pwmToneWrite(pin,2000 * i);
delay(2000);
}

delay(5000);

printf("Modified PWM frequency test end\n");

pwmSetMode(pin,PWM_MODE_BAL);
sunxi_pwm_set_enable(0);
delay(5000);
pwmSetMode(pin,PWM_MODE_MS);
sunxi_pwm_set_enable(1);
}
return 0;
}
5 changes: 0 additions & 5 deletions gpio/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1354,11 +1354,6 @@ static void doPwmClock (int argc, char *argv [])
pin = (unsigned int)strtoul (argv [2], NULL, 10) ;
clock = (unsigned int)strtoul (argv [3], NULL, 10) ;

if ((clock < 1) || (clock > 4095)) {
fprintf (stderr, "%s: clock must be between 0 and 4096\n", argv [0]) ;
exit (1) ;
}

pwmSetClock (pin,clock) ;
}

Expand Down
66 changes: 65 additions & 1 deletion gpio/readall.c
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,61 @@ static char * physNames_CM4[64] =
" GND", "GPIO3_D1",
};

static int physToWpi_3PLUS[64] =
{
-1, //0
-1, -1, //1,2
0, -1, //3,4
1, -1, //5,6
2, 3, //7,8
-1, 4, //9,10
5, 6, //11,12
7, -1, //13,14
8, 9, //15,16
-1, 10, //17,18
11, -1, //19,20
12, 13, //21,22
14, 15, //23,24
-1, 16, //25,26
17, 18, //27,28
19, -1, //29,30
20, 21, //31,32
22, -1, //33,34
23, 24, //35,36
25, 26, //37,38
-1, 27, //39,40

// Padding:
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // ... 56
-1, -1, -1, -1, -1, -1, -1, // ... 63
};

static char * physNames_3PLUS[64] =
{
NULL,
" 3.3V", "5V ",
" SDA_M3", "5V ",
" SCL_M3", "GND ",
" PWM_F", "TXD_A ",
" GND", "RXD_A ",
" PAO7", "PA12 ",
" RXD_B", "GND ",
" TXD_B", "PH8 ",
" 3.3V", "PA3 ",
" MOSI_B", "GND ",
" MISO_B", "PAO5 ",
" SCLK_B", "SSO_B ",
" GND", "PWMAO_C ",
" SDA_M0", "SCL_M0 ",
" PA2", "GND ",
" PC7", "PA4 ",
" PAO10", "GND ",
" PA13", "PA0 ",
" PA7", "PA10 ",
" GND", "PA9 ",
};


static int * physToWpi;
static char ** physNames;

Expand Down Expand Up @@ -1470,7 +1525,12 @@ void OrangePiReadAll(int model)
physNames = physNames_CM4;
alts = alts_rk3588;
break;

case PI_MODEL_3_PLUS:
printf (" +------+-----+----------+--------+---+ PI3 PLUS +---+--------+----------+-----+------+\n");
physToWpi = physToWpi_3PLUS;
physNames = physNames_3PLUS;
alts = alts_common;
break;
default:
printf ("Oops - unable to determine board type... model: %d\n", model);
break ;
Expand All @@ -1492,6 +1552,7 @@ void OrangePiReadAll(int model)
case PI_MODEL_CM4:
case PI_MODEL_3B:
case PI_MODEL_ZERO_2_W:
case PI_MODEL_3_PLUS:
for (pin = 1 ; pin <= 40; pin += 2)
readallPhys(pin);
break;
Expand Down Expand Up @@ -1591,6 +1652,9 @@ void OrangePiReadAll(int model)
case PI_MODEL_3B:
printf (" +------+-----+----------+--------+---+ PI3B +---+--------+----------+-----+------+\n");
break;
case PI_MODEL_3_PLUS:
printf (" +------+-----+----------+--------+---+ PI3 PLUS +---+--------+----------+-----+------+\n");
break;
default:
printf ("Oops - unable to determine board type... model: %d\n", model);
break ;
Expand Down
Loading

0 comments on commit 69d7f1b

Please sign in to comment.