Advertisement
Soupborsh

Pinmux table generator from cleaned input.

Jun 23rd, 2025
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.20 KB | None | 0 0
  1. /*
  2. This program is free software: you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation, either version 3 of the License, or
  5. (at your option) any later version.
  6.  
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11.  
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. */
  15.  
  16. #include <cstdio>
  17. #include <algorithm>
  18. #include <iostream>
  19. #include <sstream>
  20. #include <string>
  21.  
  22. #define ULL unsigned long long
  23. #define LL long long
  24. #define uint unsigned int
  25. #define uchar unsigned char
  26.  
  27. #define IRQ true
  28.  
  29. typedef struct {
  30.   bool type;
  31.   uchar irqbank;
  32.   uchar irqnum;
  33.   std::string name;
  34. } fun;
  35.  
  36. typedef struct {
  37.   std::string name;
  38.   fun funcs[8];
  39. } pin;
  40.  
  41. int main(void) {
  42.  
  43.   // Init table
  44.   pin table[80];
  45.   std::string line, name;
  46.   for (uchar i = 0; i < 80; i++) {
  47.     table[i].name = "-";
  48.     for (uchar j = 0; j < 8; j++) {
  49.       table[i].funcs[j].name = "-";
  50.       table[i].funcs[j].type = 0;
  51.     }
  52.   }
  53.   uint it = 0, mux, bank, num;
  54.  
  55.   // Fill the table object
  56.   std::getline(std::cin, line);
  57.  
  58.   while (line[0] != 'e') {
  59.     if (line[0] != 'P') {
  60.       std::stringstream ss(line);
  61.       if (line[0] == 'i') {
  62.         ss.ignore(1);
  63.         ss >> mux >> bank >> num;
  64.         table[it - 1].funcs[mux].type = IRQ;
  65.         table[it - 1].funcs[mux].irqbank = bank;
  66.         table[it - 1].funcs[mux].irqnum = num;
  67.         table[it - 1].funcs[mux].name = "IRQ";
  68.       } else {
  69.         ss >> mux >> name;
  70.         table[it - 1].funcs[mux].name = name;
  71.       }
  72.     } else {
  73.       it++;
  74.       table[it - 1].name = line;
  75.     }
  76.     std::getline(std::cin, line);
  77.   }
  78.  
  79.   // Print
  80.   // Header
  81.   printf("<div class=\"toccolours mw-collapsible mw-collapsed\">\nAllwinner "
  82.          "B288 GPIO multiplex functions\n<div "
  83.          "class=\"mw-collapsible-content\">\n{| class=\"wikitable\" "
  84.          "style=\"margin:auto\"\n|-\n! rowspan=\"2\" | Pin !! colspan=\"8\" | "
  85.          "function\n|-\n! 0 !! 1 !! 2 !! 3 !! "
  86.          "4 !! 5 !! 6 !! 7\n");
  87.   // Table's main part
  88.   for (uint i = 0; i < 80; i++) {
  89.     std::transform(table[i].name.begin(), table[i].name.end(),
  90.                    table[i].name.begin(), ::toupper);
  91.     printf("|-");
  92.     if (table[i].name[1] == 'C' || table[i].name[1] == 'F') {
  93.       printf(" style=\"background-color: #d6d9db;\"");
  94.     }
  95.     printf("\n| %s ", table[i].name.c_str());
  96.     for (uint j = 0; j < 8; j++) {
  97.       std::transform(table[i].funcs[j].name.begin(),
  98.                      table[i].funcs[j].name.end(),
  99.                      table[i].funcs[j].name.begin(), ::toupper);
  100.       printf(" || ");
  101.       printf("%s", table[i].funcs[j].name.c_str());
  102.       if (table[i].funcs[j].type == IRQ) {
  103.         printf(" bank: %hhu num: %hhu", table[i].funcs[j].irqbank,
  104.                table[i].funcs[j].irqnum);
  105.       }
  106.     }
  107.     putchar('\n');
  108.   }
  109.   // Footer
  110.   printf("|}\n</div>\n</div>\n");
  111.  
  112.   return 0;
  113. }
  114.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement