MCPcopy Create free account
hub / github.com/WiringPi/WiringPi / pseudoPinsSetup

Function pseudoPinsSetup

wiringPi/pseudoPins.c:76–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

74
75
76int pseudoPinsSetup(const int pinBase)
77{
78 struct wiringPiNodeStruct *node;
79 void *ptr;
80
81 node = wiringPiNewNode(pinBase, PSEUDO_PINS);
82 if (node == NULL) {
83 fprintf(stderr, "Error creating new wiringPi node");
84 return false;
85 }
86
87 node->fd = shm_open(SHARED_NAME, O_CREAT | O_RDWR, 0666);
88 if (node->fd < 0) {
89 perror("Error opening shared memory");
90 return false;
91 }
92
93 if (ftruncate(node->fd, PSEUDO_PINS * sizeof(int)) < 0) {
94 perror("Error resizing shared memory");
95 return false;
96 }
97
98 ptr = mmap(NULL, PSEUDO_PINS * sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED, node->fd, 0);
99 if (ptr == MAP_FAILED) {
100 perror("Error mapping shared memory");
101 return false;
102 }
103
104 node->data0 = (unsigned int)(uintptr_t)ptr;
105
106 node->analogRead = myAnalogRead;
107 node->analogWrite = myAnalogWrite;
108
109 return true;
110}

Callers 1

doExtensionPseudoPinsFunction · 0.85

Calls 1

wiringPiNewNodeFunction · 0.85

Tested by

no test coverage detected